still figuring out the architecture of this app

This commit is contained in:
msk
2022-09-20 15:34:38 -07:00
parent 2ab28ec5c8
commit 531f856bdc
5 changed files with 22 additions and 16 deletions
+8 -10
View File
@@ -1,3 +1,4 @@
from math import inf
import tweepy import tweepy
import secrets import secrets
@@ -10,20 +11,17 @@ class API:
API.instance = self API.instance = self
self.client = tweepy.Client( self.client = tweepy.Client(
bearer_token=secrets.bearer_token(), bearer_token=secrets.bearer_token(),
# consumer_key=secrets.api_key(), consumer_key=secrets.api_key(), consumer_secret=secrets.api_secret(),
# consumer_secret=secrets.api_secret(), access_token=secrets.access_token(), access_token_secret=secrets.access_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() posts = list()
step = util.clamp(count, 5, 100) retrieve_size = util.clamp(count, 5, 100)
retrieved_tweets = 0 retrieved_tweets = 0
pagination_token = None pagination_token = None
# while retrieved_tweets < count: # 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'])
resp = self.client.get_users_tweets(id, max_results=count) return resp
print(resp)
+1 -1
View File
@@ -1,6 +1,6 @@
## The bot's catch-up mode ## The bot's catch-up mode
# Scan all accounts for cross-company interactions. # Scan all accounts for cross-company interactions.
# Terminates when finished scanning. # Terminates when finished scanning and posting.
import os import os
import TwitterAPI as api import TwitterAPI as api
+5 -3
View File
@@ -7,6 +7,7 @@ import catchup
import listen import listen
from api import API from api import API
import util
def init_argparse(): def init_argparse():
p = argparse.ArgumentParser(description='Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.', formatter_class=RawTextHelpFormatter) 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 if args.mode is None: return
api = API() util.twAPI = API()
api.get_tweets(1390620618001838086) resp = util.twAPI.get_user_tweets(1390620618001838086, count=5)
print(resp.data)
# determine running mode # determine running mode
match args.mode.lower(): match args.mode.lower():
@@ -42,7 +44,7 @@ def main():
print('RUNNING IN CATCH-UP MODE\n') print('RUNNING IN CATCH-UP MODE\n')
catchup.run() catchup.run()
case _: 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 return
+6
View File
@@ -0,0 +1,6 @@
from collections import namedtuple
class VTweet:
def __init__(self, tweet, users: list):
self.tweet = tweet
self.users = users
+2 -2
View File
@@ -2,11 +2,11 @@
import os import os
global twAPI # Twitter API instance to share throughout program
twAPI = None twAPI = None
# returns system path to this project, which is # 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(): def get_project_dir():
return os.path.join(os.path.dirname(__file__), os.pardir) return os.path.join(os.path.dirname(__file__), os.pardir)