当前位置: 首页>>代码示例>>Python>>正文


Python Twitter.parse_tweets方法代码示例

本文整理汇总了Python中twitter.Twitter.parse_tweets方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.parse_tweets方法的具体用法?Python Twitter.parse_tweets怎么用?Python Twitter.parse_tweets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twitter.Twitter的用法示例。


在下文中一共展示了Twitter.parse_tweets方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_twitter

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import parse_tweets [as 别名]
class test_twitter(unittest.TestCase):

    def setUp(self):
        self.t = Twitter()

    def test_get_suburb(self):
        # need tests for oauth failure
        # t.get_tweet()
        # only works when you know what the most recent tweet on twitter is,
        # and it is a suburb with art in it (not Charnwood!)
        # self.assertEqual(self.t.get_suburb(), 'Charnwood', "Tweet not found")
        # self.assertEqual(self.t.get_suburb(), None, "same tweet again")
        None

    def test_parse_tweets(self):
        test = '[{"created_at":"Sat Jul 12 01:22:32 +0000 2014",'
        test = test + '"id":487768939548536840,"id_str":"487768939548536840",'
        test = test + '"text":"@mhvgovhacktest Show me a Parkes sculpture"}]'
        jsontest = json.loads(test)
        self.assertEqual(self.t.parse_tweets(jsontest), 'PARKES', "valid suburb")
        self.assertEqual(self.t.parse_tweets(jsontest), None, "same tweet again")
        test = '[{"created_at":"Sat Jul 12 01:22:32 +0000 2014",'
        test = test + '"id":487768939548536840,"id_str":"487768939548536840",'
        test = test + '"text":"@mhvgovhacktest Show me a Charnwood sculpture"}]'
        jsontest = json.loads(test)
        self.assertEqual(self.t.parse_tweets(jsontest), None, "invalid suburb")

    def tearDown(self):
        del self.t
开发者ID:PrototypeDino,项目名称:govhack2014,代码行数:31,代码来源:test_twitter.py

示例2: test_twitter

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import parse_tweets [as 别名]
class test_twitter(unittest.TestCase):

    def setUp(self):
        self.t = Twitter()

    def test_get_suburb(self):
        # need tests for oauth failure
        # t.get_tweet()
        # only works when you know what the most recent tweet on twitter is,
        # and it is a suburb with art in it (not Charnwood!)
        # self.assertEqual(self.t.get_suburb()['suburb'], 'CHARNWOOD', "Tweet not found")
        # self.assertEqual(self.t.get_suburb(), None, "same tweet again")
        None

    def test_parse_tweets(self):
        # parse tweets returns  dict {'timestamp', 'suburb', 'screen_name'}
        test = '[{"created_at":"Sat Jul 12 01:22:32 +0000 2014",'
        test = test + '"id":487768939548536840,"id_str":"487768939548536840",'
        test = test + '"text":"@mhvgovhacktest Show me a Parkes sculpture",'
        test = test + '"user":{"screen_name":"cmrn"}}]'
        jsontest = json.loads(test)
        suburb = self.t.parse_tweets(jsontest)
        ts = time.strptime("Sat Jul 12 01:22:32 +0000 2014", '%a %b %d %H:%M:%S +0000 %Y')
        tse = int(time.strftime('%s', ts))

        self.assertEqual(suburb['suburb'], 'PARKES', "valid suburb")
        self.assertEqual(suburb['screen_name'], 'cmrn', "screen name")
        self.assertEqual(suburb['timestamp'], tse, "timestamp")
        test = '[{"created_at":"Sat Jul 12 01:22:32 +0000 2014",'
        test = test + '"id":487768939548536840,"id_str":"487768939548536840",'
        test = test + '"text":"@mhvgovhacktest Show me a Parkes sculpture",'
        test = test + '"user":{"screen_name":"cmrn"}}]'
        jsontest = json.loads(test)
        suburb = self.t.parse_tweets(jsontest)
        self.assertEqual(suburb['suburb'], 'PARKES', "previous suburb")

        test = '[{"created_at":"Sat Jul 12 01:22:32 +0000 2014",'
        test = test + '"id":487768939548539999,"id_str":"487768939548536840",'
        test = test + '"text":"@mhvgovhacktest Show me a Civic sculpture",'
        test = test + '"user":{"screen_name":"cmrn"}}]'
        jsontest = json.loads(test)
        suburb = self.t.parse_tweets(jsontest)
        ts = time.strptime("Sat Jul 12 01:22:32 +0000 2014", '%a %b %d %H:%M:%S +0000 %Y')
        tse = int(time.strftime('%s', ts))
        self.assertEqual(suburb['suburb'], 'CITY', "valid suburb")
        self.assertEqual(suburb['screen_name'], 'cmrn', "screen name")
        self.assertEqual(suburb['timestamp'], tse, "timestamp")

    def tearDown(self):
        del self.t
开发者ID:mbainrot,项目名称:govhack2014,代码行数:52,代码来源:test_twitter.py


注:本文中的twitter.Twitter.parse_tweets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。