Advertisement
Bspammer

Untitled

Apr 15th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import praw
  2. import wordcloud
  3. import os
  4. import re
  5.  
  6. r = praw.Reddit("/u/Bspammer")
  7.  
  8. def subredditWordCloud(subreddit):
  9.     sub = r.get_subreddit(subreddit)
  10.     comments = sub.get_comments(limit=None)
  11.  
  12.     rawtext = ""
  13.     for c in comments:
  14.         rawtext += c.body + " :::: "
  15.  
  16.     rawtext = re.sub(r'[^a-zA-Z0-9\': ]', '', rawtext)
  17.  
  18.     f = open("wordclouds/" + subreddit + "Comments.txt", "w")
  19.     f.write(rawtext)
  20.     f.close()
  21.  
  22.     wc = wordcloud.WordCloud(max_words=1000, width=1920, height=1080,
  23.                              stopwords=wordcloud.STOPWORDS.copy(), margin=10, random_state=1).generate(rawtext.lower())
  24.  
  25.     wc.to_file("wordclouds/" + subreddit + "Wordcloud.png")
  26.  
  27. subredditWordCloud("rocketleague")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement