Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 3194
1
import sys
2
3
import numpy as np
4
from IPython.core.display import Image
5
6
import praw
7
8
9
10
#subreddit = reddit.get_subreddit("showerthoughts")
11
12
#top_submissions = subreddit.get_top(limit=100)
13
14
#update old praw usage to current version (7.6.0)
15
#please notice that new Reddit Object usage, especially the praw.ini file
16
reddit = praw.Reddit("BayesianMethodsForHackers",user_agent="BMFH")
17
top_submissions = reddit.subreddit("showerthoughts").new(limit=100)
18
19
20
n_sub = int( sys.argv[1] ) if sys.argv[1] else 1
21
22
i = 0
23
while i < n_sub:
24
top_submission = next(top_submissions)
25
i+=1
26
top_post = top_submission.title
27
28
upvotes = []
29
downvotes = []
30
contents = []
31
32
for sub in top_submissions:
33
try:
34
ratio = sub.upvote_ratio
35
ups = int(round((ratio*sub.score)/(2*ratio - 1)) if ratio != 0.5 else round(sub.score/2))
36
upvotes.append(ups)
37
downvotes.append(ups - sub.score)
38
contents.append(sub.title)
39
except Exception as e:
40
continue
41
votes = np.array( [ upvotes, downvotes] ).T
42