Created
November 21, 2012 17:55
-
-
Save fmasanori/4126471 to your computer and use it in GitHub Desktop.
Python Reddit MongoDB Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib | |
import pymongo | |
con = pymongo.Connection('mongodb://localhost', | |
safe = True) | |
db = con.reddit | |
stories = db.stories | |
url = 'http://www.reddit.com/r/Python/.json' | |
resp = urllib.urlopen(url).read() | |
parsed = json.loads(resp) | |
for item in parsed['data']['children']: | |
stories.insert(item['data']) | |
print ('Reddit stories inserted') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment