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
0 commit comments