Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- import cPickle as pickle
- import matplotlib.pyplot as plt
- import numpy as np
- import praw
- def collect_data():
- print("Connecting to Reddit...")
- reddit = praw.Reddit(client_id='aaaaa',
- client_secret='bbbbb',
- password='ccccc',
- user_agent='ddddd',
- username='eeeee')
- print("Connected.")
- print("-----")
- submissions_counter = Counter()
- comments_counter = Counter()
- counter = 0
- for submission in reddit.subreddit('korea').submissions(start=1483228800,
- end=1510364058):
- print(counter)
- counter += 1
- print(submission.title)
- submissions_counter[submission.author] += 1
- submission.comments.replace_more(limit=30)
- for comment in submission.comments.list():
- comments_counter[comment.author] += 1
- pickle.dump(submissions_counter, open("submissions.p", "wb"))
- pickle.dump(comments_counter, open("comments.p", "wb"))
- def load_data():
- submissions_counter = pickle.load(open("submissions.p", "rb"))
- comments_counter = pickle.load(open("comments.p", "rb"))
- return submissions_counter, comments_counter
- def make_graph(names, comments):
- pos = np.arange(500) * 20
- plt.figure(figsize=(15, 200))
- plt.barh(pos, comments, height=10, align='center')
- plt.yticks(pos, names)
- plt.xlabel("Number of comments")
- plt.tight_layout()
- plt.ylim([-20, 10000])
- plt.gca().invert_yaxis()
- for i, v in enumerate(comments):
- plt.text(v + 5, i * 20 + 2, str(v),
- color='blue', fontweight='bold')
- plt.savefig('submission.png')
- s, c = load_data()
- c_most = c.most_common(500)
- a = {x: c[x] for x in c if c[x] >= 30}
- i = 0
- for each in a:
- i += 1
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement