added patchwork code for backing up queue
This commit is contained in:
+19
-1
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import datetime
|
import datetime
|
||||||
|
import asyncio
|
||||||
|
import shutil
|
||||||
|
|
||||||
import twint
|
import twint
|
||||||
|
|
||||||
@@ -159,6 +161,8 @@ async def process_queue(ttweets_dict: dict) -> int:
|
|||||||
ttweet = ttweets_dict[key]
|
ttweet = ttweets_dict[key]
|
||||||
if await TwAPI.instance.post_ttweet(ttweet, is_catchup=True):
|
if await TwAPI.instance.post_ttweet(ttweet, is_catchup=True):
|
||||||
ttweets_posted += 1
|
ttweets_posted += 1
|
||||||
|
print('resting for 60s...')
|
||||||
|
await asyncio.sleep(60)
|
||||||
ttweets_dict.pop(key)
|
ttweets_dict.pop(key)
|
||||||
# TODO: add ttweet.tweet_id to some success list
|
# TODO: add ttweet.tweet_id to some success list
|
||||||
except:
|
except:
|
||||||
@@ -184,14 +188,28 @@ async def run(program_args):
|
|||||||
global PROGRAM_ARGS
|
global PROGRAM_ARGS
|
||||||
global safe_to_post_tweets
|
global safe_to_post_tweets
|
||||||
PROGRAM_ARGS = program_args
|
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()
|
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:
|
while True:
|
||||||
ttweets_dict = await get_cross_talent_tweets(queue_path)
|
ttweets_dict = await get_cross_talent_tweets(queue_path)
|
||||||
print(f'found {len(ttweets_dict)} cross-company tweets')
|
print(f'found {len(ttweets_dict)} cross-company tweets')
|
||||||
if safe_to_post_tweets:
|
if safe_to_post_tweets:
|
||||||
if await process_queue(ttweets_dict) == 0:
|
if await process_queue(ttweets_dict) == 0:
|
||||||
print('Posted no new tweets; we\'re caught up!')
|
print('Posted no new tweets; we\'re caught up!')
|
||||||
return True
|
os.remove(queue_backup) # keep updated queue
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
print('Tweets were not retrieved cleanly.')
|
print('Tweets were not retrieved cleanly.')
|
||||||
|
os.remove(queue_path) # keep backup queue
|
||||||
return False
|
return False
|
||||||
+2
-3
@@ -212,14 +212,13 @@ class TwAPI:
|
|||||||
ret += f'\n{util.ttweet_to_url(ttweet)}'
|
ret += f'\n{util.ttweet_to_url(ttweet)}'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
img_media_id_task = asyncio.create_task(self.get_ttweet_image_media_id(ttweet))
|
|
||||||
text = create_text()
|
text = create_text()
|
||||||
try:
|
try:
|
||||||
print('posting main tweet')
|
print('posting main tweet')
|
||||||
twt_resp = await self.post_tweet(text)
|
twt_resp = await self.post_tweet(text)
|
||||||
twt_id = twt_resp.data['id']
|
twt_id = twt_resp.data['id']
|
||||||
print('waiting on reply img')
|
print('creating reply img')
|
||||||
media_id = await img_media_id_task
|
media_id = await self.get_ttweet_image_media_id(ttweet)
|
||||||
print('posting reply tweet')
|
print('posting reply tweet')
|
||||||
await self.post_tweet(reply_to_tweet=twt_id, media_id=media_id,)
|
await self.post_tweet(reply_to_tweet=twt_id, media_id=media_id,)
|
||||||
print('successfully posted ttweet!')
|
print('successfully posted ttweet!')
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
Reference in New Issue
Block a user