add logic to open tweet to notify missing scorers
This commit is contained in:
@@ -31,6 +31,7 @@ wordlinator = "wordlinator.app:sync_main"
|
|||||||
update = "wordlinator.app:sync_update"
|
update = "wordlinator.app:sync_update"
|
||||||
show-user = "wordlinator.app:sync_show_user"
|
show-user = "wordlinator.app:sync_show_user"
|
||||||
show-missing = "wordlinator.app:sync_show_missing"
|
show-missing = "wordlinator.app:sync_show_missing"
|
||||||
|
tweet-missing = "wordlinator.app:sync_tweet_missing"
|
||||||
db-load = "wordlinator.app:load_db_scores"
|
db-load = "wordlinator.app:load_db_scores"
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
|
|||||||
@@ -119,6 +119,14 @@ async def show_missing(
|
|||||||
print_missing_names(wordle_day, missing_names)
|
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():
|
def _get_day():
|
||||||
parser = argparse.ArgumentParser("wordlinator")
|
parser = argparse.ArgumentParser("wordlinator")
|
||||||
days = parser.add_mutually_exclusive_group()
|
days = parser.add_mutually_exclusive_group()
|
||||||
@@ -168,5 +176,9 @@ def sync_show_missing():
|
|||||||
asyncio.run(show_missing(wordle_day=wordle_day))
|
asyncio.run(show_missing(wordle_day=wordle_day))
|
||||||
|
|
||||||
|
|
||||||
|
def sync_tweet_missing():
|
||||||
|
asyncio.run(tweet_missing())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sync_main()
|
sync_main()
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import datetime
|
|||||||
import enum
|
import enum
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import urllib.parse
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
import authlib.integrations.httpx_client
|
import authlib.integrations.httpx_client
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
@@ -94,6 +96,11 @@ class TwitterClient(httpx.AsyncClient):
|
|||||||
SEARCH_PATH = "tweets/search/recent"
|
SEARCH_PATH = "tweets/search/recent"
|
||||||
USER_PATH = "users/by/username/{username}"
|
USER_PATH = "users/by/username/{username}"
|
||||||
TWEETS_PATH = "users/{user_id}/tweets"
|
TWEETS_PATH = "users/{user_id}/tweets"
|
||||||
|
POST_TWEET_PATH = "tweets"
|
||||||
|
|
||||||
|
TWEET_INTENT_URL = "https://twitter.com/intent/tweet"
|
||||||
|
|
||||||
|
MAX_TWEET_LENGTH = 260
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -189,6 +196,18 @@ class TwitterClient(httpx.AsyncClient):
|
|||||||
async def get_wordlegolf_tweets(self):
|
async def get_wordlegolf_tweets(self):
|
||||||
return self._build_wordle_tweets(await self.search_tweets("#WordleGolf"))
|
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():
|
async def main():
|
||||||
client = TwitterClient()
|
client = TwitterClient()
|
||||||
|
|||||||
Reference in New Issue
Block a user