diff --git a/src/catchup.py b/src/catchup.py index 821468e..af8635a 100644 --- a/src/catchup.py +++ b/src/catchup.py @@ -6,6 +6,8 @@ import traceback import datetime +import asyncio +import shutil import twint @@ -159,6 +161,8 @@ async def process_queue(ttweets_dict: dict) -> int: ttweet = ttweets_dict[key] if await TwAPI.instance.post_ttweet(ttweet, is_catchup=True): ttweets_posted += 1 + print('resting for 60s...') + await asyncio.sleep(60) ttweets_dict.pop(key) # TODO: add ttweet.tweet_id to some success list except: @@ -184,14 +188,28 @@ async def run(program_args): global PROGRAM_ARGS global safe_to_post_tweets PROGRAM_ARGS = program_args + + # in case we we experience failure and we're left with blank queue.txt + # TODO: create TweetQueue class to organize file IO better; move all backup operations to there + queue_backup = os.path.join(util.get_project_dir(), 'queue_in_progress.txt') queue_path = get_queue_path() + + if os.path.exists(queue_backup): + shutil.copyfile(queue_backup, queue_path) + else: + shutil.copyfile(queue_path, queue_backup) + + ret = None + while True: ttweets_dict = await get_cross_talent_tweets(queue_path) print(f'found {len(ttweets_dict)} cross-company tweets') if safe_to_post_tweets: if await process_queue(ttweets_dict) == 0: print('Posted no new tweets; we\'re caught up!') - return True + os.remove(queue_backup) # keep updated queue + return True else: print('Tweets were not retrieved cleanly.') + os.remove(queue_path) # keep backup queue return False \ No newline at end of file diff --git a/src/twapi.py b/src/twapi.py index 342e765..60198ce 100644 --- a/src/twapi.py +++ b/src/twapi.py @@ -212,14 +212,13 @@ class TwAPI: ret += f'\n{util.ttweet_to_url(ttweet)}' return ret - img_media_id_task = asyncio.create_task(self.get_ttweet_image_media_id(ttweet)) text = create_text() try: print('posting main tweet') twt_resp = await self.post_tweet(text) twt_id = twt_resp.data['id'] - print('waiting on reply img') - media_id = await img_media_id_task + print('creating reply img') + media_id = await self.get_ttweet_image_media_id(ttweet) print('posting reply tweet') await self.post_tweet(reply_to_tweet=twt_id, media_id=media_id,) print('successfully posted ttweet!') diff --git a/twitter profile/banner.png b/twitter profile/banner.png new file mode 100644 index 0000000..7b9ddfa Binary files /dev/null and b/twitter profile/banner.png differ