本文整理汇总了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
示例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