add logic to open tweet to notify missing scorers

This commit is contained in:
2022-06-02 12:37:39 -05:00
parent 7239eba8dc
commit 45705a4e67
3 changed files with 32 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ wordlinator = "wordlinator.app:sync_main"
update = "wordlinator.app:sync_update"
show-user = "wordlinator.app:sync_show_user"
show-missing = "wordlinator.app:sync_show_missing"
tweet-missing = "wordlinator.app:sync_tweet_missing"
db-load = "wordlinator.app:load_db_scores"
[tool.mypy]

View File

@@ -119,6 +119,14 @@ async def show_missing(
print_missing_names(wordle_day, missing_names)
async def tweet_missing():
sheets_client = wordlinator.sheets.SheetsClient()
missing_names = sheets_client.get_missing_names()
twitter_client = wordlinator.twitter.TwitterClient()
await twitter_client.notify_missing(missing_names)
def _get_day():
parser = argparse.ArgumentParser("wordlinator")
days = parser.add_mutually_exclusive_group()
@@ -168,5 +176,9 @@ def sync_show_missing():
asyncio.run(show_missing(wordle_day=wordle_day))
def sync_tweet_missing():
asyncio.run(tweet_missing())
if __name__ == "__main__":
sync_main()

View File

@@ -4,6 +4,8 @@ import datetime
import enum
import os
import re
import urllib.parse
import webbrowser
import authlib.integrations.httpx_client
import dateutil.parser
@@ -94,6 +96,11 @@ class TwitterClient(httpx.AsyncClient):
SEARCH_PATH = "tweets/search/recent"
USER_PATH = "users/by/username/{username}"
TWEETS_PATH = "users/{user_id}/tweets"
POST_TWEET_PATH = "tweets"
TWEET_INTENT_URL = "https://twitter.com/intent/tweet"
MAX_TWEET_LENGTH = 260
def __init__(
self,
@@ -189,6 +196,18 @@ class TwitterClient(httpx.AsyncClient):
async def get_wordlegolf_tweets(self):
return self._build_wordle_tweets(await self.search_tweets("#WordleGolf"))
def open_tweet(self, msg):
param = urllib.parse.urlencode({"text": msg})
webbrowser.open(f"{self.TWEET_INTENT_URL}?{param}")
async def notify_missing(self, names):
header = "Still missing a few #WordleGolf Players today!"
msg = header
while names:
while len(msg) < self.MAX_TWEET_LENGTH and names:
msg += f" @{names.pop()}"
self.open_tweet(msg)
async def main():
client = TwitterClient()