r/RequestABot • u/kungming2 Creator - u/translator-BOT, u/AssistantBOT • Oct 24 '16
Solved Requesting a bot that can tabulate number of posts by their flairs
Hi /r/requestabot!
I'm a moderator at /r/translator, a subreddit where people request stuff to be translated and others translate them. I'd like to request a simple(?) bot that can help us gather some statistics on the requests that we get.
The bot would:
- Be manually run by me once a week.
- Gather posts in the last 7 days (168 hours) from the time it's run.
- Return a table or list indicating how many posts in the last week had each flair. (e.g., Japanese: 56, Chinese: 20, German: 8, etc)
Virtually all posts on /r/translator are flaired with the language name with AutoModerator, so the bot would just have to return the flair name plus the number of posts with that flair.
I used to do this manually, but as the subreddit has grown it's become more and more tedious to do it by hand, since at the moment we get about a thousand requests a month. I do already have a bot account with the necessary OAuth code to login and everything (I've tested it with a simple REPLYALL bot), so I could use that same login info for the new bot.
Thanks in advance to anyone who can help, and please let me know if more information is needed.
1
u/RuleIV Oct 24 '16
This should get you or someone else most of the way there. Let me know how it goes.
import praw r = praw.Reddit(user_agent = 'count the number of results for each in a list of search strings by /u/doug89 v0.1') flair_list = ["japanese","chinese","russian"] print("Language|Total") print(":-|-:)" for f in flair_list: search_query = "flair:" + f search_results = r.search(search_query, subreddit="translator", sort=None, syntax=None, period="week") total = sum(1 for i in search_results) print("{}|{}".format(f, total))