Skip to content

Instantly share code, notes, and snippets.

@rebornix
Created April 11, 2013 12:51
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rebornix/5363138 to your computer and use it in GitHub Desktop.
Save rebornix/5363138 to your computer and use it in GitHub Desktop.
parse rss to markdown
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