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
+1 -1
View File
@@ -2,7 +2,7 @@
*Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.* *Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.*
...because some folks are that desperate. Like me! ...because some folks are that desperate. Like me!
**This project is intended to run [this account](https://twitter.com/NijiHoloEN_Msgs).** **This project is intended to run [this account](https://twitter.com/NijiHolo_EN_ID).**
## Roadmap ## Roadmap
* Read past tweets of members from both companies * Read past tweets of members from both companies
+1 -1
View File
@@ -4,7 +4,7 @@
# --- [Myth] --- # --- [Myth] ---
gawrgura 1283657064410017793 gawrgura 1283657064410017793
watsonameliaen 283656034305769472 watsonameliaen 1283656034305769472
moricalliope 1283653858510598144 moricalliope 1283653858510598144
ninomaeinanis 1283650008835743744 ninomaeinanis 1283650008835743744
takanashikiara 1283646922406760448 takanashikiara 1283646922406760448
View File
+41 -4
View File
@@ -11,10 +11,12 @@ import twint
from util import * from util import *
from talent_lists import * from talent_lists import *
from api import TwAPI from twapi import TwAPI
import talenttweet as tt 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(): def get_local_queue():
# f = open(os.path.join(get_project_dir(), 'queue.txt')) # f = open(os.path.join(get_project_dir(), 'queue.txt'))
pass pass
@@ -29,10 +31,17 @@ def get_user_tweet_ids(id, limit=None):
c.Store_object_tweets_list = tweets c.Store_object_tweets_list = tweets
c.Hide_output = True c.Hide_output = True
user_str = f'{id} ({util.get_username(id)})'
print(f'Finding tweets from {user_str})')
try:
twint.run.Search(c) twint.run.Search(c)
return [x.id for x in tweets] 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 # while Queue.txt has lines present
# attempt to deserialize first line of Queue.txt # attempt to deserialize first line of Queue.txt
# exit program if failed, stating error # exit program if failed, stating error
@@ -43,8 +52,31 @@ def work_on_queue():
# we're done! post tweet announcing done with archives # we're done! post tweet announcing done with archives
pass 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(): async def run():
pass
# if Queue.txt exists # if Queue.txt exists
# work through the tweets in Queue.txt # work through the tweets in Queue.txt
# else # else
@@ -53,3 +85,8 @@ async def run():
# create Queue.txt and save all tweets through there # create Queue.txt and save all tweets through there
# post a tweet announcing archival intent # 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)
+1 -1
View File
@@ -9,7 +9,7 @@ import talent_lists
import api_secrets import api_secrets
import catchup import catchup
import listen import listen
from api import TwAPI from twapi import TwAPI
MODES_HELP_STR = '''mode to run the bot at: MODES_HELP_STR = '''mode to run the bot at:
l,listen: listen for new tweets from all accounts; will not terminate unless error occurs l,listen: listen for new tweets from all accounts; will not terminate unless error occurs
+4 -1
View File
@@ -7,14 +7,17 @@ niji_exid = dict()
talents = dict() talents = dict()
def __create_dict(file, _dict): def __create_dict(file, _dict):
print(f'Initializing talents\' account list from {file}...')
global talents global talents
with open(file, 'r') as f: with open(file, 'r') as f:
for line in f: for line in f:
words = line.split() words = line.split()
if len(words) == 2 and line[0] != '#': if len(words) == 2 and line[0] != '#':
name, id = line.split() name, id = line.split()
_dict[int(id)] = name
talents[int(id)] = name talents[int(id)] = name
name = util.get_username_online(id) # attempt to get updated name
talents[int(id)] = name
_dict[int(id)] = name
def init(): def init():
global holo_en global holo_en
global holo_id global holo_id
+2 -1
View File
@@ -3,7 +3,7 @@ import platform
import pytz import pytz
from api import * from twapi import *
import talent_lists import talent_lists
class TalentTweet: class TalentTweet:
@@ -121,6 +121,7 @@ class TalentAPITweet(TalentTweet):
if tweet and mrq: if tweet and mrq:
self.tweet = tweet self.tweet = tweet
elif tweet_id: elif tweet_id:
tweet_id = int(tweet_id)
resp = TwAPI.instance.get_tweet_response(tweet_id) resp = TwAPI.instance.get_tweet_response(tweet_id)
self.tweet = resp.data self.tweet = resp.data
mrq = TwAPI.get_mrq(self.tweet, resp) mrq = TwAPI.get_mrq(self.tweet, resp)
View File
+7 -3
View File
@@ -5,11 +5,11 @@ import os
import twint import twint
from tweetcapture import TweetCapture from tweetcapture import TweetCapture
from talent_lists import * import talent_lists
import talenttweet as tt import talenttweet as tt
# returns system path to this project, which is # returns system path to this project, which is
# up one level from this file's directory (src). # up one level from this file's directory (effective path: ..../src/../).
def get_project_dir(): def get_project_dir():
return os.path.join(os.path.dirname(__file__), os.pardir) return os.path.join(os.path.dirname(__file__), os.pardir)
@@ -43,6 +43,9 @@ def ttweet_to_url(ttweet):
return f'https://twitter.com/{username}/status/{ttweet.tweet_id}' return f'https://twitter.com/{username}/status/{ttweet.tweet_id}'
def get_username(user_id): def get_username(user_id):
return talent_lists.talents.get(user_id, f'#{id}')
def get_username_online(user_id):
c = twint.Config() c = twint.Config()
c.User_id = user_id c.User_id = user_id
c.Store_object = True c.Store_object = True
@@ -50,6 +53,7 @@ def get_username(user_id):
try: try:
twint.run.Lookup(c) twint.run.Lookup(c)
user = twint.output.users_list[0] user = twint.output.users_list[0]
twint.output.users_list.clear()
return user.username return user.username
except: except:
return talents.get(user_id, f'#{user_id}') return f'#{user_id}'