如何将twitter feed条目保存到django模型?

时间:2012-01-31 16:26:34

标签: xml django-models twitter

所以,这是一个我想要保存到模型的推特:#stackoverflow。我可以使用feedparser将Feed中的每个条目作为字典。数据看起来像这样:

{ '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)}

我想将所有这些信息保存到模型中。我该如何构建我的模型?

1 个答案:

答案 0 :(得分:1)

我会从这样的事情开始

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

并根据需要添加更多字段。