From 531f856bdc1583cc8103af647ce1157e5781bd6c Mon Sep 17 00:00:00 2001 From: msk <15199219+muskit@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:34:38 -0700 Subject: [PATCH] still figuring out the architecture of this app --- src/api.py | 18 ++++++++---------- src/catchup.py | 2 +- src/main.py | 8 +++++--- src/structs.py | 6 ++++++ src/util.py | 4 ++-- 5 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 src/structs.py diff --git a/src/api.py b/src/api.py index ce13d84..98fe192 100644 --- a/src/api.py +++ b/src/api.py @@ -1,3 +1,4 @@ +from math import inf import tweepy import secrets @@ -10,20 +11,17 @@ class API: API.instance = self self.client = tweepy.Client( bearer_token=secrets.bearer_token(), - # consumer_key=secrets.api_key(), - # consumer_secret=secrets.api_secret(), - # access_token=secrets.access_token(), - # access_token_secret=secrets.access_secret() + consumer_key=secrets.api_key(), consumer_secret=secrets.api_secret(), + access_token=secrets.access_token(), access_token_secret=secrets.access_secret() ) - def get_tweets(self, id: int, count=5): + def get_user_tweets(self, id: int, count=inf): posts = list() - step = util.clamp(count, 5, 100) + retrieve_size = util.clamp(count, 5, 100) retrieved_tweets = 0 pagination_token = None - # while retrieved_tweets < count: - - resp = self.client.get_users_tweets(id, max_results=count) - print(resp) \ No newline at end of file + # while retrieved_tweets < count: # or we haven't reached the end of user's tweets + resp = self.client.get_users_tweets(id, max_results=retrieve_size, media_fields=['url'], expansions=['entities.mentions.username', 'referenced_tweets.id.author_id']) + return resp \ No newline at end of file diff --git a/src/catchup.py b/src/catchup.py index 66d4af3..2147173 100644 --- a/src/catchup.py +++ b/src/catchup.py @@ -1,6 +1,6 @@ ## The bot's catch-up mode # Scan all accounts for cross-company interactions. -# Terminates when finished scanning. +# Terminates when finished scanning and posting. import os import TwitterAPI as api diff --git a/src/main.py b/src/main.py index 787b286..30e7f9b 100644 --- a/src/main.py +++ b/src/main.py @@ -7,6 +7,7 @@ import catchup import listen from api import API +import util def init_argparse(): p = argparse.ArgumentParser(description='Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.', formatter_class=RawTextHelpFormatter) @@ -30,8 +31,9 @@ def main(): if args.mode is None: return - api = API() - api.get_tweets(1390620618001838086) + util.twAPI = API() + resp = util.twAPI.get_user_tweets(1390620618001838086, count=5) + print(resp.data) # determine running mode match args.mode.lower(): @@ -42,7 +44,7 @@ def main(): print('RUNNING IN CATCH-UP MODE\n') catchup.run() case _: - print('\ninvalid mode. run with no arguments for help page, including mode list.') + print('\ninvalid mode. run with no arguments or "-h" for help page, including mode list.') return diff --git a/src/structs.py b/src/structs.py new file mode 100644 index 0000000..ed96681 --- /dev/null +++ b/src/structs.py @@ -0,0 +1,6 @@ +from collections import namedtuple + +class VTweet: + def __init__(self, tweet, users: list): + self.tweet = tweet + self.users = users \ No newline at end of file diff --git a/src/util.py b/src/util.py index 2f1cb56..f8914d1 100644 --- a/src/util.py +++ b/src/util.py @@ -2,11 +2,11 @@ import os -global twAPI +# Twitter API instance to share throughout program twAPI = None # returns system path to this project, which is -# up one level from this file's directory. +# up one level from this file's directory (src). def get_project_dir(): return os.path.join(os.path.dirname(__file__), os.pardir)