From dd08a66b5df2640c388e3c60910ce33e8c8995db Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Wed, 3 Jan 2024 20:20:40 +0530 Subject: [PATCH] add new script, --- user-flair-usage/main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 user-flair-usage/main.py diff --git a/user-flair-usage/main.py b/user-flair-usage/main.py new file mode 100644 index 0000000..c099006 --- /dev/null +++ b/user-flair-usage/main.py @@ -0,0 +1,40 @@ +import praw +from collections import defaultdict +import os + +client_id = os.environ["REDDIT_CLIENT_ID"] +client_secret = os.environ["REDDIT_CLIENT_SECRET"] +reddit_pass = os.environ["REDDIT_PASSWORD"] +username = os.environ["REDDIT_USERNAME"] +user_agent = 'User Flair Usage' +sub = "developersIndia" + +# Create a Reddit instance +reddit = praw.Reddit( + client_id=client_id, + client_secret=client_secret, + username=username, + password=reddit_pass, + user_agent=user_agent +) + +# Select the subreddit +subreddit = reddit.subreddit(sub) + +# Initialize a dictionary to count flairs +flair_count = defaultdict(int) + +# Iterate over all the flairs +for flair in subreddit.flair(limit=None): + flair_count[flair['flair_text']] += 1 + +# Convert the dictionary to a list of tuples and sort it by the count +sorted_flairs = sorted(flair_count.items(), key=lambda x: x[1], reverse=True) + +# Print the sorted list of flairs and their counts +for flair, count in sorted_flairs: + print(f"Flair: {flair}, Count: {count}") + +# Calculate and print the total count of all flairs +total_count = sum(flair_count.values()) +print(f"Total count of all flairs: {total_count}") \ No newline at end of file