Last active
August 29, 2015 14:04
-
-
Save yagays/cb48d68a2c4204642206 to your computer and use it in GitHub Desktop.
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
#!/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 "=========" |
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
#!/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