fundamental progression, fixes

This commit is contained in:
muskit
2022-09-25 18:31:50 -07:00
committed by msk
parent 65a0c898e9
commit 8f4b8679df
9 changed files with 60 additions and 15 deletions
+44 -7
View File
@@ -11,10 +11,12 @@ import twint
from util import *
from talent_lists import *
from api import TwAPI
from twapi import TwAPI
import talenttweet as tt
## Returns list of tweets present in queue.txt
def get_queue_file():
return f'{util.get_project_dir()}/queue.txt'
def get_local_queue():
# f = open(os.path.join(get_project_dir(), 'queue.txt'))
pass
@@ -29,10 +31,17 @@ def get_user_tweet_ids(id, limit=None):
c.Store_object_tweets_list = tweets
c.Hide_output = True
twint.run.Search(c)
return [x.id for x in tweets]
user_str = f'{id} ({util.get_username(id)})'
print(f'Finding tweets from {user_str})')
try:
twint.run.Search(c)
return [x.id for x in tweets]
except:
print(f'Had trouble getting tweets from {user_str}')
return list()
def work_on_queue():
def work_on_queue(file):
print('TODO: implement work_on_queue')
# while Queue.txt has lines present
# attempt to deserialize first line of Queue.txt
# exit program if failed, stating error
@@ -43,8 +52,31 @@ def work_on_queue():
# we're done! post tweet announcing done with archives
pass
# If queue.txt doesn't exist, creates and populates it.
# Returns a list of sorted and filtered TalentTweets (should
# be equivalent to queue.txt)
def create_ttweets_queue(path) -> list:
print('Creating ttweets queue')
if not os.path.exists(path):
ttweets = list()
with open(path, 'x') as f:
for talent_id in talents.keys():
tweet_ids = get_user_tweet_ids(talent_id)
print(f'retrieved {len(tweet_ids)} tweets')
for tweet_id in tweet_ids:
ttweet = tt.TalentAPITweet(tweet_id)
if ttweet.is_cross_company():
ttweets.append(ttweet)
ttweets.sort(key=lambda ttweet: ttweet.tweet_id)
for ttweet in ttweets:
f.write(f'{ttweet.serialize()}\n')
return ttweets
else:
return list()
async def run():
pass
# if Queue.txt exists
# work through the tweets in Queue.txt
# else
@@ -52,4 +84,9 @@ async def run():
# sort the list by tweet_id
# create Queue.txt and save all tweets through there
# post a tweet announcing archival intent
# work through the tweets in Queue.txt
# work through the tweets in Queue.txt
queue_path = get_queue_file()
if os.path.exists(queue_path):
work_on_queue(queue_path)
else:
ttweets = create_ttweets_queue(queue_path)