a littel change
This commit is contained in:
parent
16ce41545e
commit
178ad090fa
|
|
@ -225,9 +225,9 @@ TWITTER_CONFIG = {
|
||||||
"user_search_url": "https://api.twitter.com/2/users/by/username/{0}",
|
"user_search_url": "https://api.twitter.com/2/users/by/username/{0}",
|
||||||
"contents_search_url": "https://api.twitter.com/2/users/{0}/tweets?max_results=100&tweet.fields=text,created_at&exclude=replies,retweets",
|
"contents_search_url": "https://api.twitter.com/2/users/{0}/tweets?max_results=100&tweet.fields=text,created_at&exclude=replies,retweets",
|
||||||
"monitor_accounts": [
|
"monitor_accounts": [
|
||||||
"FoxNews",
|
{"name": "FoxNews", "id": ""},
|
||||||
"WhiteHouse",
|
{"name": "WhiteHouse", "id": "1879644163769335808"},
|
||||||
"sama",
|
{"name": "sama", "id": ""},
|
||||||
"PressSec",
|
{"name": "PressSec", "id": ""},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -53,17 +53,19 @@ class TwitterRetriever:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def monitor_accounts(self):
|
def monitor_accounts(self):
|
||||||
for account in self.monitor_account_list:
|
for account_dict in self.monitor_account_list:
|
||||||
logger.info(f"Monitoring account: {account}")
|
user_name = account_dict["name"]
|
||||||
|
user_id = account_dict["id"]
|
||||||
|
logger.info(f"Monitoring account: {user_name}")
|
||||||
logger.info(f"Sleeping for {self.sleep_time} seconds")
|
logger.info(f"Sleeping for {self.sleep_time} seconds")
|
||||||
time.sleep(self.sleep_time)
|
# time.sleep(self.sleep_time)
|
||||||
result_list = []
|
result_list = []
|
||||||
user = self.search_user(account)
|
if user_id is None or user_id == "":
|
||||||
if user is None:
|
user = self.search_user(user_name)
|
||||||
continue
|
if user is None:
|
||||||
username = user["data"]["username"]
|
continue
|
||||||
user_id = str(user["data"]["id"])
|
user_id = str(user["data"]["id"])
|
||||||
contents = self.search_contents(username, user_id)
|
contents = self.search_contents(user_name, user_id)
|
||||||
if contents is None:
|
if contents is None:
|
||||||
continue
|
continue
|
||||||
twitter_contents = contents["data"]
|
twitter_contents = contents["data"]
|
||||||
|
|
@ -75,7 +77,7 @@ class TwitterRetriever:
|
||||||
text = content["text"]
|
text = content["text"]
|
||||||
result = {
|
result = {
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"user_name": username,
|
"user_name": user_name,
|
||||||
"timestamp": timestamp_ms,
|
"timestamp": timestamp_ms,
|
||||||
"date_time": beijing_time_str,
|
"date_time": beijing_time_str,
|
||||||
"text": text
|
"text": text
|
||||||
|
|
@ -86,7 +88,7 @@ class TwitterRetriever:
|
||||||
self.db_twitter_content.insert_data_to_mysql(result_df)
|
self.db_twitter_content.insert_data_to_mysql(result_df)
|
||||||
logger.info(f"Inserted {len(result_df)} rows into twitter_content")
|
logger.info(f"Inserted {len(result_df)} rows into twitter_content")
|
||||||
else:
|
else:
|
||||||
logger.warning(f"No data inserted for account: {account}")
|
logger.warning(f"No data inserted for account: {user_name}")
|
||||||
|
|
||||||
def transform_datetime(self, datetime_text: str):
|
def transform_datetime(self, datetime_text: str):
|
||||||
utc_time = datetime.strptime(datetime_text, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=pytz.UTC)
|
utc_time = datetime.strptime(datetime_text, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=pytz.UTC)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue