fixing some queue logic
This commit is contained in:
+6
-1
@@ -81,10 +81,15 @@ async def process_queue(priority_tweet_ids: list[str]=None) -> bool:
|
|||||||
try:
|
try:
|
||||||
while not queue.is_empty():
|
while not queue.is_empty():
|
||||||
ttweet = queue.get_next_ttweet()
|
ttweet = queue.get_next_ttweet()
|
||||||
|
if ttweet.tweet_id in queue.finished_ttweets:
|
||||||
|
print('skipping finished tweet...')
|
||||||
|
queue.good(ttweet.tweet_id)
|
||||||
|
continue
|
||||||
|
|
||||||
tweet_was_successful = await TwAPI.instance.post_ttweet(ttweet)
|
tweet_was_successful = await TwAPI.instance.post_ttweet(ttweet)
|
||||||
|
|
||||||
print('running queue.good()...')
|
print('running queue.good()...')
|
||||||
queue.good()
|
queue.good(ttweet.tweet_id)
|
||||||
if tweet_was_successful:
|
if tweet_was_successful:
|
||||||
ttweets_posted += 1
|
ttweets_posted += 1
|
||||||
print(f'({ttweets_posted}/{queued_ttweets_count}) done')
|
print(f'({ttweets_posted}/{queued_ttweets_count}) done')
|
||||||
|
|||||||
+7
-8
@@ -22,7 +22,7 @@ class TalentTweetQueue:
|
|||||||
self.__sorted = False
|
self.__sorted = False
|
||||||
self.finished_user_dates: dict[int, str] = dict()
|
self.finished_user_dates: dict[int, str] = dict()
|
||||||
self.ttweets_dict: dict[int, tt.TalentTweet] = dict()
|
self.ttweets_dict: dict[int, tt.TalentTweet] = dict()
|
||||||
self.finished_ttweets: list[int] = list()
|
self.finished_ttweets: set[int] = set()
|
||||||
|
|
||||||
## file check, backup copy
|
## file check, backup copy
|
||||||
if os.path.exists(self.queue_backup_path):
|
if os.path.exists(self.queue_backup_path):
|
||||||
@@ -74,7 +74,7 @@ class TalentTweetQueue:
|
|||||||
try:
|
try:
|
||||||
with open(self.finished_ttweets_path, 'r') as f:
|
with open(self.finished_ttweets_path, 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
self.finished_ttweets.append(int(line))
|
self.finished_ttweets.add(int(line))
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
|
|
||||||
@@ -102,12 +102,11 @@ class TalentTweetQueue:
|
|||||||
|
|
||||||
## Call when the TalentTweet retrieved from get_next_ttweet() was
|
## Call when the TalentTweet retrieved from get_next_ttweet() was
|
||||||
# posted successfully.
|
# posted successfully.
|
||||||
def good(self):
|
def good(self, tweet_id: int):
|
||||||
with open(self.current_ttweet_path, 'r') as f:
|
try: os.remove(self.current_ttweet_path)
|
||||||
ttweet = tt.TalentTweet.deserialize(f.readline())
|
except: pass
|
||||||
|
|
||||||
self.add_finished_tweet(ttweet.tweet_id)
|
self.add_finished_tweet(tweet_id)
|
||||||
os.remove(self.current_ttweet_path)
|
|
||||||
self.save_file()
|
self.save_file()
|
||||||
self.is_good = True
|
self.is_good = True
|
||||||
|
|
||||||
@@ -129,7 +128,7 @@ class TalentTweetQueue:
|
|||||||
print('done')
|
print('done')
|
||||||
|
|
||||||
def add_finished_tweet(self, id):
|
def add_finished_tweet(self, id):
|
||||||
self.finished_ttweets.append(id)
|
self.finished_ttweets.add(id)
|
||||||
with open(self.finished_ttweets_path, 'a') as f:
|
with open(self.finished_ttweets_path, 'a') as f:
|
||||||
f.write(f'{id}\n')
|
f.write(f'{id}\n')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user