Advertisement
Guest User

test.py

a guest
Dec 18th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. import praw
  2. import matplotlib.pyplot as plt
  3. from collections import Counter
  4.  
  5. #top secret data
  6. reddit = praw.Reddit(client_id='id', \
  7.                      client_secret='secret', \
  8.                      user_agent='Scraper', \
  9.                      username='username', \
  10.                      password='password')
  11.  
  12. subredditname = "asu"
  13.  
  14. subreddit = reddit.subreddit(subredditname)
  15.  
  16. top_subbreddit = subreddit.top()
  17. count = 0
  18. max = 10000
  19. print('success')
  20. words = []
  21. wordCount = {}
  22. commonWords = {'that','this','and','of','the','for','I','it','has','in',
  23. 'you','to','was','but','have','they','a','is','','be','on','are','an','or',
  24. 'at','as','do','if','your','not','can','my','their','them','they','with',
  25. 'at','about','would','like','there','You','from','get','just','more','so',
  26. 'me','more','out','up','some','will','how','one','what',"don't",'should',
  27. 'could','did','no','know','were','did',"it's",'This','he','The','we',
  28. 'all','when','had','see','his','him','who','by','her','she','our','thing','-',
  29. 'now','what','going','been','we',"I'm",'than','any','because','We','even',
  30. 'said','only','want','other','into','He','what','i','That','thought',
  31. 'think',"that's",'Is','much','too','still','got','its','theres','Cant','Lmao',
  32. 'My','these','those','[deleted]','if','It'}
  33.  
  34. for submission in subreddit.top(limit=500):
  35.     submission.comments.replace_more(limit=0)
  36.     for top_level_comment in submission.comments:
  37.         count += 1
  38.         if(count == max):
  39.             break
  40.         tempWords = top_level_comment.body.split(' ')
  41.         filter(str.isalpha, words)
  42.         words += [word for word in tempWords if word not in commonWords]
  43.     if(count == max):
  44.             break
  45.  
  46. word_count = Counter(words)
  47.  
  48. top_words = word_count.most_common(10)
  49. topWords = [word[0] for word in top_words]
  50. topWordsCount = [value[1] for value in top_words]
  51.  
  52. plt.title('Top comments for: r/' + subredditname)
  53. plt.pie(topWordsCount, labels=topWords,autopct='%1.1f%%',
  54.         shadow=True, startangle=90)
  55. plt.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
  56. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement