Skip to content

Commit 61767bc

Browse files
committed
Updated Ch4 to Python3, updated reddit example
1 parent 45323f8 commit 61767bc

File tree

3 files changed

+205
-238
lines changed

3 files changed

+205
-238
lines changed

Chapter4_TheGreatestTheoremNeverTold/Chapter4.ipynb

Lines changed: 152 additions & 175 deletions
Large diffs are not rendered by default.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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( "crazyideas" )
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+
#while "i.imgur.com" not in top_submission.url:
20+
# #make sure it is linking to an image, not a webpage.
21+
# top_submission = next(top_submissions)
22+
i+=1
23+
24+
#print("Post contents: \n", top_submission.title)
25+
top_post = top_submission.title
26+
#top_submission.replace_more_comments(limit=5, threshold=0)
27+
#print(top_post_url)
28+
29+
upvotes = []
30+
downvotes = []
31+
contents = []
32+
"""_all_comments = top_submission.comments
33+
all_comments=[]
34+
for comment in _all_comments:
35+
try:
36+
#ups = int(round((ratio*comment.score)/(2*ratio - 1)) if ratio != 0.5 else round(comment.score/2))
37+
#upvotes.append(ups)
38+
#downvotes.append(ups - comment.score)
39+
scores.append( comment.score )
40+
contents.append( comment.body )
41+
except Exception as e:
42+
continue
43+
"""
44+
for sub in top_submissions:
45+
try:
46+
ratio = reddit.get_submission(sub.permalink).upvote_ratio
47+
ups = int(round((ratio*sub.score)/(2*ratio - 1)) if ratio != 0.5 else round(sub.score/2))
48+
upvotes.append(ups)
49+
downvotes.append(ups - sub.score)
50+
contents.append(sub.title)
51+
except Exception as e:
52+
continue
53+
votes = np.array( [ upvotes, downvotes] ).T

Chapter4_TheGreatestTheoremNeverTold/top_pic_comments.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)