From dfe4410e2b50a880070af0045742578c1d322bf2 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 24 Nov 2021 11:17:05 -0500 Subject: [PATCH] [+] Create function to find news channels --- src/process/twitter_process.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/process/twitter_process.py b/src/process/twitter_process.py index 636b5b7..04772dd 100644 --- a/src/process/twitter_process.py +++ b/src/process/twitter_process.py @@ -146,6 +146,28 @@ def select_user_sample() -> None: write(file, json_stringify(Sample(most_popular, sample))) +def get_news_channels() -> list[str]: + """ + Find news channels + + Run this after download_all_tweets(api, 'TwitterNews') + + Precondition: + - /user/TwitterNews.json exists. + + :return: A list of news channel screen names + """ + # Find news channels in retweets from TwitterNews + news_channels = {'TwitterNews'} + for tweet in json.loads(read(f'{TWEETS_DIR}/user/TwitterNews.json')): + text: str = tweet['full_text'] + if text.startswith('RT @'): + user = text[4:].split(':')[0] + news_channels.add(user) + + return list(news_channels) + + def load_user_sample() -> Sample: """ Load the selected sample