| Download
Project: ⛏️ hsy development
Path: examples/bayesian-methods-for-hackers / Chapter4_TheGreatestTheoremNeverTold / top_showerthoughts_submissions.py
Views: 3194import sys12import numpy as np3from IPython.core.display import Image45import praw6789#subreddit = reddit.get_subreddit("showerthoughts")1011#top_submissions = subreddit.get_top(limit=100)1213#update old praw usage to current version (7.6.0)14#please notice that new Reddit Object usage, especially the praw.ini file15reddit = praw.Reddit("BayesianMethodsForHackers",user_agent="BMFH")16top_submissions = reddit.subreddit("showerthoughts").new(limit=100)171819n_sub = int( sys.argv[1] ) if sys.argv[1] else 12021i = 022while i < n_sub:23top_submission = next(top_submissions)24i+=125top_post = top_submission.title2627upvotes = []28downvotes = []29contents = []3031for sub in top_submissions:32try:33ratio = sub.upvote_ratio34ups = int(round((ratio*sub.score)/(2*ratio - 1)) if ratio != 0.5 else round(sub.score/2))35upvotes.append(ups)36downvotes.append(ups - sub.score)37contents.append(sub.title)38except Exception as e:39continue40votes = np.array( [ upvotes, downvotes] ).T4142