如何将twitter feed条目保存到django模型中?
问题描述:
所以,这里是我想要保存到模型的推文Feed:#stackoverflow。我可以使用feedparser以字典的形式获取Feed中的每个条目。数据看起来像这样:如何将twitter feed条目保存到django模型中?
{ 'author': u'stackfeed (StackOverflow)',
'author_detail': { 'href': u'http://twitter.com/stackfeed',
'name': u'stackfeed (StackOverflow)'},
'authors': [ { 'href': u'http://twitter.com/stackfeed',
'name': u'stackfeed (StackOverflow)'}],
'content': [ { 'base': u'http://search.twitter.com/search.atom?lang=en&q=stackoverflow',
'language': u'en-US',
'type': u'text/html',
'value': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... <a href="http://t.co/vYqLsWj5">http://t.co/vYqLsWj5</a>'}],
'guidislink': True,
'href': u'http://twitter.com/stackfeed',
'id': u'tag:search.twitter.com,2005:164382321993187328',
'link': u'http://twitter.com/stackfeed/statuses/164382321993187328',
'links': [ { 'href': u'http://twitter.com/stackfeed/statuses/164382321993187328',
'rel': u'alternate',
'type': u'text/html'},
{ 'href': u'http://a2.twimg.com/sticky/default_profile_images/default_profile_3_normal.png',
'rel': u'image',
'type': u'image/png'}],
'published': u'2012-01-31T16:19:34Z',
'published_parsed': time.struct_time(tm_year=2012, tm_mon=1, tm_mday=31, tm_hour=16, tm_min=19, tm_sec=34, tm_wday=1, tm_yday=31, tm_isdst=0),
'summary': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... <a href="http://t.co/vYqLsWj5">http://t.co/vYqLsWj5</a>',
'title': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... http://t.co/vYqLsWj5',
'title_detail': { 'base': u'http://search.twitter.com/search.atom?lang=en&q=stackoverflow',
'language': u'en-US',
'type': u'text/plain',
'value': u'How to inject a single factory instance to multiple repositories and unit of work using ninject?: First, I have ... http://t.co/vYqLsWj5'},
u'twitter_geo': u'',
u'twitter_lang': u'en',
u'twitter_metadata': u'',
u'twitter_result_type': u'recent',
u'twitter_source': u'<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>',
'updated': u'2012-01-31T16:19:34Z',
'updated_parsed': time.struct_time(tm_year=2012, tm_mon=1, tm_mday=31, tm_hour=16, tm_min=19, tm_sec=34, tm_wday=1, tm_yday=31, tm_isdst=0)}
我想将所有这些信息保存到模型中。我应该如何构建我的模型?
答
我就开始像这样
class Author(models.Model):
name = models.CharField(...
uri = models. ...
class Tweet(models.Model):
author = models.ForeignKey('Author'), related_name='tweets')
title
content = models.TextField
published_datetime
summary
,并根据需要添加更多的字段。
谢谢你的回复。如果Twitter决定更改其中一个字段,或者将来添加或删除一对字段,您不认为这会是一个问题吗? – archmage 2012-02-01 14:23:19
@archmage如果twitter更改字段,您将不得不更改解析器。 – Meitham 2012-02-01 15:34:30
你为什么这么认为?我只是得到饲料并将其转储到数据库。即使我不得不在这里或那里改变几件事情,如果我不需要改变模型,这将非常有帮助。 – archmage 2012-02-01 17:14:23