still figuring out the architecture of this app
This commit is contained in:
+8
-10
@@ -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)
|
||||
# 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
|
||||
+1
-1
@@ -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
|
||||
|
||||
+5
-3
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from collections import namedtuple
|
||||
|
||||
class VTweet:
|
||||
def __init__(self, tweet, users: list):
|
||||
self.tweet = tweet
|
||||
self.users = users
|
||||
+2
-2
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user