Created
April 11, 2013 12:51
-
-
Save rebornix/5363138 to your computer and use it in GitHub Desktop.
parse rss to markdown
This file contains hidden or 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 feedparser | |
rss_url = "" | |
feed = feedparser.parse( rss_url ) | |
items = feed["items"] | |
for item in items: | |
time = item[ "published_parsed" ] | |
title = item[ "title" ].encode('gb18030') | |
fileName = str(time.tm_year) + '-' + str(time.tm_mon) + '-' + str(time.tm_mday) + '-' + title + '.md' | |
fileName = fileName.replace('/', '') | |
f = open(fileName,'w') | |
value = item["content"][0]['value'].encode('gb18030') | |
f.write('---\nlayout: post\ntitle: ' + title + '\n') | |
f.write('''status: publish | |
published: true | |
meta: | |
_edit_last: "1" | |
type: post | |
tags: | |
--- | |
''') | |
f.write(value) | |
print 'end' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment