[O] Filter news channels

This commit is contained in:
Hykilpikonna
2021-11-24 17:00:44 -05:00
parent c41931d3eb
commit 1cb1f58e1a
3 changed files with 24 additions and 4 deletions
+4 -2
View File
@@ -58,8 +58,10 @@ if __name__ == '__main__':
#####################
# Data collection - Step C2.3
# (After step P2) Download all tweets from the news channels we selected.
for u in load_user_sample().english_news:
download_all_tweets(api, u)
# for u in load_user_sample().english_news:
# download_all_tweets(api, u)
# Filter out news channels that have been blocked by twitter or don't exist anymore
# filter_news_channels()
#####################
# Data processing - Step P3
+18
View File
@@ -184,6 +184,24 @@ def get_english_news_channels() -> list[str]:
return list(news_channels)
def filter_news_channels() -> None:
"""
Filter out news channels that don't exist anymore or have been banned by Twitter.
Precondition:
- Run this after downloading all tweets from the news channels in Step 2.3 in main.
:return: None
"""
sample = load_user_sample()
for u in list(sample.english_news):
u = u.lower()
if not (os.path.isfile(f'{TWEETS_DIR}/processed/{u}.json')
or os.path.isfile(f'{TWEETS_DIR}/users/{u}.json')):
sample.english_news.remove(u)
write(f'{USER_DIR}/processed/sample.json', json_stringify(sample))
def load_user_sample() -> Sample:
"""
Load the selected sample
+2 -2
View File
@@ -87,8 +87,8 @@ def download_all_tweets(api: API, screen_name: str,
debug(f'- {screen_name}: Unauthorized. Probably a private account, ignoring.')
return
except NotFound:
debug(f'- {screen_name}: Not found. Probably a deleted account, writing []')
tweets = []
debug(f'- {screen_name}: Not found. Probably a deleted account, ignoring.')
return
# This person has no tweets, done. (By the way, we discovered that @lorde has no tweets but has
# 7 million followers... wow!)