Skip to content

Commit d14068b

Browse files
committed
Ch4 updated the praw to 7.6.0 in top_showerthoughts_submissions to make it work, and other small updates
1 parent e96f611 commit d14068b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Chapter4_TheGreatestTheoremNeverTold/top_showerthoughts_submissions.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66
import praw
77

88

9-
reddit = praw.Reddit("BayesianMethodsForHackers")
10-
subreddit = reddit.get_subreddit("showerthoughts")
119

12-
top_submissions = subreddit.get_top(limit=100)
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+
1319

1420
n_sub = int( sys.argv[1] ) if sys.argv[1] else 1
1521

1622
i = 0
1723
while i < n_sub:
1824
top_submission = next(top_submissions)
1925
i+=1
20-
2126
top_post = top_submission.title
2227

2328
upvotes = []
@@ -26,7 +31,7 @@
2631

2732
for sub in top_submissions:
2833
try:
29-
ratio = reddit.get_submission(sub.permalink).upvote_ratio
34+
ratio = sub.upvote_ratio
3035
ups = int(round((ratio*sub.score)/(2*ratio - 1)) if ratio != 0.5 else round(sub.score/2))
3136
upvotes.append(ups)
3237
downvotes.append(ups - sub.score)

0 commit comments

Comments
 (0)