Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132923 views
License: OTHER
1
import sys
2
3
import numpy as np
4
from IPython.core.display import Image
5
6
import praw
7
8
9
reddit = praw.Reddit("BayesianMethodsForHackers")
10
subreddit = reddit.get_subreddit("showerthoughts")
11
12
top_submissions = subreddit.get_top(limit=100)
13
14
n_sub = int( sys.argv[1] ) if sys.argv[1] else 1
15
16
i = 0
17
while i < n_sub:
18
top_submission = next(top_submissions)
19
i+=1
20
21
top_post = top_submission.title
22
23
upvotes = []
24
downvotes = []
25
contents = []
26
27
for sub in top_submissions:
28
try:
29
ratio = reddit.get_submission(sub.permalink).upvote_ratio
30
ups = int(round((ratio*sub.score)/(2*ratio - 1)) if ratio != 0.5 else round(sub.score/2))
31
upvotes.append(ups)
32
downvotes.append(ups - sub.score)
33
contents.append(sub.title)
34
except Exception as e:
35
continue
36
votes = np.array( [ upvotes, downvotes] ).T
37