Skip to content

Instantly share code, notes, and snippets.

@yagays
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yagays/cb48d68a2c4204642206 to your computer and use it in GitHub Desktop.
Save yagays/cb48d68a2c4204642206 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import feedparser
import pymongo
import datetime
anond_feed = feedparser.parse("http://anond.hatelabo.jp/rss")
client = pymongo.MongoClient()
db = client["anond"]
posts = db.posts
for entry in anond_feed["entries"]:
entry_id = entry["id"][25:]
entry_title = entry["title"]
entry_text = entry["content"][0]["value"]
entry_updated = entry["updated"]
entry_link = entry["link"]
if posts.find_one({"id":entry_id}):
# print str(entry_id) + " is already inserted"
pass
else:
posts.insert({"id":entry_id,"title":entry_title,"text":entry_text,"updated":entry_updated,"link":entry_link})
print str(entry_id) + " inserted"
print str(datetime.datetime.now()) + " / " + str(posts.count()) + " posts archived"
print "========="
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# usage: python load_anond.py <id>
import pymongo
import sys
client = pymongo.MongoClient()
db = client["anond"]
posts = db.posts
for e in posts.find({"id":sys.argv[1]}):
print "title: " + e["title"]
print e["text"].replace("<p>","").replace("</p>","")
print "Updated: " + e["updated"]
print "link: " + e["link"]
print ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment