Skip to content

Instantly share code, notes, and snippets.

@1900
Created August 22, 2012 07:06
Show Gist options
  • Save 1900/3423220 to your computer and use it in GitHub Desktop.
Save 1900/3423220 to your computer and use it in GitHub Desktop.
feedparser test
# import required modules
import feedparser, MySQLdb
# set up connection to MySQL database
db = MySQLdb.connect(host='host',user='user',passwd='pass',db='dbname')
cursor=db.cursor()
# fetch feed and turn into feedparser object
d = feedparser.parse('http://65s.org/feed/')
# determine number of entries in feed, which is used in processing loop
x = len(d.entries)
# processing loop - for each entry, selects certain attributes and inserts them into a MySQL table. Also converts the RSS entry date into a MySQL date
for i in range(x):
d2 = d.entries[i].description
cursor.execute("""INSERT INTO test (title, description, url) VALUES (%s,%s,%s)""", (d.entries[i].title, d.entries[i].description, d.entries[i].link))
# commit insertions to table (optional)
db.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment