Closed dmd2588 closed 7 years ago
import praw
import time
import pprint
import json
pp = pprint.PrettyPrinter(indent=1)
reddit = praw.Reddit(client_id=CLIENT,
client_secret=SECRET,
password=PASS,
user_agent='Python',
username='tlam51')
users_table = []
subreddits_table = []
comments_table = []
submissions_table = []
sr_ray = ['fireemblemheroes', 'ProgrammerHumor', 'food']
for sr_name in sr_ray:
sr = reddit.subreddit(sr_name)
sr_path = sr._info_path()
sr_info = reddit.request("GET", sr_path)
subreddits_table.append({"id": sr_info["data"]["id"],
"title": sr_info["data"]["title"],
"display_name": sr_info["data"]["display_name"],
"accounts_active": sr_info["data"]["accounts_active"],
"subscribers": sr_info["data"]["subscribers"],
"created": sr_info["data"]["created"]})
for m in sr.moderator:
uname = m.name
user_path = reddit.redditor(uname)._info_path()
user_info = reddit.request("GET", user_path)
ckarma = user_info["data"]["comment_karma"]
lkarma = user_info["data"]["link_karma"]
created = user_info["data"]["created"]
user_id = user_info["data"]["id"]
users_table.append({"id": user_id,
"name": uname,
"comment_karma": ckarma,
"link_karma": lkarma,
"created": created})
for c in m.comments.new(limit=1):
comments_table.append({"id": c.id,
"created": c.created,
"body": c.body,
"author": c.author.id,
"link_id": c.link_id,
"score": c.score,
"subreddit_id": c.subreddit.id})
submission = reddit.submission(id=c.link_id[3:])
a_name = 'None'
if submission.author is not None:
a_name = submission.author.name
submissions_table.append({"id": submission.id,
"title": submission.title,
"score": submission.score,
"url": submission.url,
"author": a_name,
"over_18": submission.over_18})
pp.pprint(users_table)
pp.pprint(subreddits_table)
pp.pprint(comments_table)
pp.pprint(submissions_table)
[{'comment_karma': 190,
'created': 1405828618.0,
'email': 'None',
'id': u'hh8mr',
'link_karma': 335,
'name': u'batman_jr'},
{'comment_karma': 25418,
'created': 1331171212.0,
'email': u'poizan@poizan.dk',
'id': u'74344',
'link_karma': 768,
'name': u'poizan42'},
{'comment_karma': 56846,
'created': 1287044616.0,
'email': u'ooer@live.com',
'id': u'4fer6',
'link_karma': 18834,
'name': u'Ooer'}]
[{'accounts_active': 921,
'created': 1484806197.0,
'display_name': u'FireEmblemHeroes',
'id': u'3imv0',
'subscribers': 52790,
'title': u"Fire Emblem Heroes - Nintendo's Latest Mobile Game"},
{'accounts_active': 603,
'created': 1327266711.0,
'display_name': u'ProgrammerHumor',
'id': u'2tex6',
'subscribers': 199848,
'title': u'Programmer Humor'},
{'accounts_active': 1338,
'created': 1201275191.0,
'display_name': u'food',
'id': u'2qh55',
'subscribers': 10979227,
'title': u'food'}]
[{'author': u'hh8mr',
'body': u'comment 2',
'created': 1488274311.0,
'id': u'deaw2vi',
'link_id': u't3_5th7sz',
'score': 1,
'subreddit_id': u'3imxi'},
{'author': u'74344',
'body': u'> Despite claiming ownership, Canada provides no medical or social services to any of the inhabitants of Hans Island.\n\nYou could also say that they do provide medical and social services to all the inhabitants though.',
'created': 1490098110.0,
'id': u'df7d781',
'link_id': u't3_60h6ga',
'score': 2,
'subreddit_id': u'2qqjc'},
{'author': u'4fer6',
'body': u"Spilled a glass of diet Pepsi all over Cash 'n' Guns (first time playing). It was of course an accident and they immediately offered to help clean them, and failing that buy me the game again.\n\nThankfully, because it was diet (no sugar) the cards were able to be saved and now you couldn't tell it ever happened. ",
'created': 1490146785.0,
'id': u'df8425r',
'link_id': u't3_60nyom',
'score': 3,
'subreddit_id': u'2qmjp'}]
[{'author': u'batman_jr',
'id': u'5th7sz',
'over_18': False,
'score': 1,
'title': u'Test',
'url': u'https://www.reddit.com/r/FireEmblemHeroesTest/comments/5th7sz/test/'},
{'author': u'FallBlue',
'id': u'60h6ga',
'over_18': False,
'score': 637,
'title': u'TIL that Greenland is actually part of North America, is ruled by Denmark, and is icier than Iceland.',
'url': u'https://www.britannica.com/place/Greenland'},
{'author': u'bigfatlittlefat',
'id': u'60nyom',
'over_18': False,
'score': 55,
'title': u'What is the worst thing someone did to your boardgame?',
'url': u'https://www.reddit.com/r/boardgames/comments/60nyom/what_is_the_worst_thing_someone_did_to_your/'}]
Some code for collecting data using https://github.com/praw-dev/praw