【发布时间】:2009-08-30 17:38:25
【问题描述】:
我正在尝试使用 Python 解析 Twitter RSS 提要并将信息放入 sqlite 数据库中。这是一个例子:
MiamiPete: today's "Last Call" is now up http://bit.ly/MGDzu #stocks #stockmarket #finance #money
我要做的是为主要内容 (Miami Pete…now up) 创建一列,为 URL (http://bit.ly/MGDzu) 创建一列,为主题标签(股票、股市、金融、货币)创建四个单独的列。我一直在玩弄如何做到这一点。
任何建议将不胜感激!
附:下面是我一直在玩的一些代码——你可以看到我最初尝试创建一个名为“tiny_url”的变量并将其拆分,它似乎确实这样做了,但是这种微弱的尝试并没有接近解决所提到的问题多于。 :)
def store_feed_items(id, items):
""" Takes a feed_id and a list of items and stored them in the DB """
for entry in items:
c.execute('SELECT entry_id from RSSEntries WHERE url=?', (entry.link,))
tinyurl = entry.summary ### I added this in
print tinyurl.split('http') ### I added this in
if len(c.fetchall()) == 0:
c.execute('INSERT INTO RSSEntries (id, url, title, content, tinyurl, date, tiny) VALUES (?,?,?,?,?,?,?)', (id, entry.link, entry.title, entry.summary, tinyurl, strftime("%Y-%m-%d %H:%M:%S",entry.updated_parsed), tiny ))
【问题讨论】:
标签: python string sqlite split bit.ly