Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import matplotlib.pyplot as plt
- reddit = praw.Reddit(
- client_id="client_id",
- client_secret="client_secret",
- user_agent="user_agent"
- )
- AllSubmissions = []
- mp = {}
- words = []
- for submission in reddit.subreddit("dataisbeautiful").hot(limit=1000):
- AllSubmissions.append((submission.title, submission.score))
- if "[Topic][Open]" not in submission.title:
- for i in submission.title.split():
- if i.isalpha():
- words.append(i.lower())
- WordUpvote = []
- stopWords = ["me", "my", "myself", "we", "our", "ours", "ourselves", "you", "your", "yours", "yourself", "yourselves", "he", "him", "his", "himself", "she", "her", "hers", "herself", "it", "its", "itself", "they", "them", "their", "theirs", "themselves", "what", "which", "who", "whom", "this", "that", "these", "those", "am", "is", "are", "was", "were", "be", "been", "being", "have", "has", "had", "having", "do", "does", "did", "doing", "a", "an", "the", "and", "but", "if", "or", "because", "as", "until", "while", "of", "at", "by", "for", "with", "about", "against", "between", "into", "through", "during", "before", "after", "above", "below", "to", "from", "up", "down", "in", "out", "on", "off", "over", "under", "again", "further", "then", "once", "here", "there", "when", "where", "why", "how", "all", "any", "both", "each", "few", "more", "most", "other", "some", "such", "no", "nor", "not", "only", "own", "same", "so", "than", "too", "very", "s", "t", "can", "will", "just", "don", "should", "now"]
- words = list(set(words))
- for word in words:
- scores = []
- for sub in AllSubmissions:
- t = sub[0]
- s = sub[1]
- if word in t:
- scores.append(s)
- if len(scores)>5 and word.lower() not in stopWords:
- avg = int(sum(scores)/len(scores))
- WordUpvote.append([avg, word])
- WordUpvote.sort(key=lambda x:int(x[0]))
- length = 20
- x = [b for a, b in WordUpvote[len(WordUpvote)-length:]]
- y = [a for a, b in WordUpvote[len(WordUpvote)-length:]]
- plt.bar(x, y)
- plt.ylim(0,)
- ax = plt.axes()
- plt.title("These words were included in the title of the most upvoted posts (given that they appeared in at least 5 posts)")
- plt.xlabel("Words")
- plt.ylabel("Number of upvotes")
- ax.set_xticklabels(labels=x, fontsize = 8)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement