Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active March 6, 2018 23:06
Show Gist options
  • Save fmasanori/5923142 to your computer and use it in GitHub Desktop.
Save fmasanori/5923142 to your computer and use it in GitHub Desktop.
reddit insert mongo
import json
from urllib.request import urlopen
import pymongo
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.reddit
stories = db.stories
reddit_page = urlopen('http://www.reddit.com/r/Python/.json')
parsed = json.loads(reddit_page.read().decode('utf-8'))
for item in parsed['data']['children']:
stories.insert(item['data'])
print ('Reddit stories ok...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment