Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions nexus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
load_dotenv()

class Utils:
MAX_TWEETS = 3200 # Maximum allowed tweets per Twitter API (user timeline)

def __init__(self):
api_key = os.getenv("API_KEY")
api_secret = os.getenv("API_SECRET")
Expand All @@ -32,6 +34,13 @@ def user_lookup_tweepy(self, user: str, quantity: int):
:param quantity: amount of tweets you want to retrieve

"""
# Validate and cap quantity to prevent denial of service
if not isinstance(quantity, int) or quantity <= 0:
raise ValueError("Quantity must be a positive integer")
if quantity > self.MAX_TWEETS:
logger.info(f"Requested quantity {quantity} exceeds limit; capping to {self.MAX_TWEETS}.")
quantity = self.MAX_TWEETS

query: List[Dict] = []

tweets = tweepy.Cursor(
Expand Down Expand Up @@ -133,6 +142,4 @@ def create_topics(self, documents: List[Dict], id_to_cluster_label: Dict, id_fie
bot = Utils()
lookup = bot.user_lookup_sns("JoeBiden", 5000)
print(len(lookup))
print(lookup[-1])


print(lookup[-1])