From 5adb2b17b5937d17bb739941a1a28c4f215f869f Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Mon, 22 Nov 2021 16:41:54 -0500 Subject: [PATCH] [+] Create get user popularity ranking --- src/process/twitter_process.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/process/twitter_process.py b/src/process/twitter_process.py index 96a600e..de95e5a 100644 --- a/src/process/twitter_process.py +++ b/src/process/twitter_process.py @@ -64,6 +64,21 @@ def load_users_popularity(user_dir: str = './data/twitter/user/') -> list[UserPo return [UserPopularity(*u) for u in json.loads(read(f'{user_dir}/processed/popularity.json'))] +def get_user_popularity_ranking(user: str, user_dir: str = './data/twitter/user/') -> int: + """ + Get a user's popularity ranking. This is not used in data analysis, just for curiosity. + + :param user: Username + :param user_dir: Download directory + :return: User's popularity ranking + """ + pop = load_users_popularity(user_dir) + for i in range(len(pop)): + if pop[i].username == user: + return i + 1 + return -1 + + class Posting(NamedTuple): """ Posting data (whether or not a posting is covid-related)