本文整理汇总了Python中twitter.Twitter.new方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.new方法的具体用法?Python Twitter.new怎么用?Python Twitter.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter.Twitter
的用法示例。
在下文中一共展示了Twitter.new方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_twitter_pictures
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_update_twitter_pictures(self):
sources = []
for screen_name in ('a', 'b', 'c'):
auth_entity = oauth_twitter.TwitterAuth(
id='id', token_key='key', token_secret='secret',
user_json=json.dumps({'name': 'Ryan',
'screen_name': screen_name,
'profile_image_url': 'http://pi.ct/ure',
}))
auth_entity.put()
sources.append(Twitter.new(None, auth_entity=auth_entity).put())
user_objs = [{'screen_name': sources[0].id(),
'profile_image_url': 'http://pi.ct/ure',
}, {'screen_name': sources[1].id(),
'profile_image_url_https': 'http://new/pic_normal.jpg',
'profile_image_url': 'http://bad/http',
}]
cron.TWITTER_USERS_PER_LOOKUP = 2
self.expect_urlopen(cron.TWITTER_API_USER_LOOKUP % 'a,c',
json.dumps(user_objs))
self.expect_urlopen(cron.TWITTER_API_USER_LOOKUP % 'b',
json.dumps(user_objs))
self.mox.ReplayAll()
resp = cron.application.get_response('/cron/update_twitter_pictures')
self.assertEqual(200, resp.status_int)
# self.assertEquals('http://pi.ct/ure', sources[0].get().picture)
# self.assertEquals('http://new/pic.jpg', sources[1].get().picture)
self.assertEquals('https://twitter.com/a/profile_image?size=original',
sources[0].get().picture)
self.assertEquals('https://twitter.com/b/profile_image?size=original',
sources[1].get().picture)
示例2: test_new_massages_profile_image
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_new_massages_profile_image(self):
"""We should use profile_image_url_https and drop '_normal' if possible."""
user = json.loads(self.auth_entity.user_json)
user['profile_image_url_https'] = 'https://foo_normal.xyz'
self.auth_entity.user_json = json.dumps(user)
self.assertEqual('https://foo.xyz', Twitter.new(self.handler, auth_entity=self.auth_entity).picture)
示例3: test_get_activities
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_get_activities(self):
self.expect_urlopen('https://api.twitter.com/1.1/statuses/user_timeline.json?'
'include_entities=true&count=0',
json.dumps([as_twitter_test.TWEET]))
self.mox.ReplayAll()
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
self.assert_equals([as_twitter_test.ACTIVITY], tw.get_activities())
示例4: test_canonicalize_syndication_url
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_canonicalize_syndication_url(self):
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
for url in (
"http://www.twitter.com/username/012345",
"https://www.twitter.com/username/012345",
"http://twitter.com/username/012345",
):
self.assertEqual("https://twitter.com/username/012345", tw.canonicalize_syndication_url(url))
示例5: test_new_massages_profile_image
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_new_massages_profile_image(self):
"""We should use profile_image_url_https and drop '_normal' if possible."""
user = json.loads(self.auth_entity.user_json)
user["profile_image_url_https"] = "https://foo_normal.xyz"
self.auth_entity.user_json = json.dumps(user)
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
# self.assertEqual('https://foo.xyz', tw.picture)
self.assertEqual("https://twitter.com/snarfed_org/profile_image?size=original", tw.picture)
示例6: test_new
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_new(self):
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
self.assertEqual(self.auth_entity, tw.auth_entity.get())
self.assertEqual('my_key', tw.as_source.access_token_key)
self.assertEqual('my_secret', tw.as_source.access_token_secret)
self.assertEqual('snarfed_org', tw.key.string_id())
self.assertEqual('http://pi.ct/ure', tw.picture)
self.assertEqual('Ryan Barrett', tw.name)
self.assertEqual('https://twitter.com/snarfed_org', tw.url)
self.assertEqual('https://twitter.com/snarfed_org', tw.silo_url())
示例7: test_new
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_new(self):
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
self.assertEqual(self.auth_entity, tw.auth_entity.get())
self.assertEqual("my_key", tw.gr_source.access_token_key)
self.assertEqual("my_secret", tw.gr_source.access_token_secret)
self.assertEqual("snarfed_org", tw.key.string_id())
self.assertEqual("https://twitter.com/snarfed_org/profile_image?size=original", tw.picture)
self.assertEqual("Ryan Barrett", tw.name)
self.assertEqual("https://twitter.com/snarfed_org", tw.url)
self.assertEqual("https://twitter.com/snarfed_org", tw.silo_url())
示例8: test_get_like
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_get_like(self):
"""get_like() should use the Response stored in the datastore."""
like = {
"objectType": "activity",
"verb": "like",
"id": "tag:twitter.com,2013:222",
"object": {"url": "http://my/favorite"},
}
models.Response(id="tag:twitter.com,2013:000_favorited_by_222", response_json=json.dumps(like)).put()
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
self.assert_equals(like, tw.get_like("unused", "000", "222"))
示例9: test_get_like
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_get_like(self):
"""get_like() should use the Response stored in the datastore."""
like = {
'objectType': 'activity',
'verb': 'like',
'id': 'tag:twitter.com,2013:222',
'object': {'url': 'http://my/favorite'},
}
models.Response(id='tag:twitter.com,2013:000_favorited_by_222',
response_json=json.dumps(like)).put()
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
self.assert_equals(like, tw.get_like('unused', '000', '222'))
示例10: test_get_like_fallback
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_get_like_fallback(self):
"""If there's no Response in the datastore, fall back to get_activities."""
tweet = copy.deepcopy(as_twitter_test.TWEET)
tweet['favorite_count'] = 1
self.expect_urlopen(
'https://api.twitter.com/1.1/statuses/show.json?id=100&include_entities=true',
json.dumps(tweet))
self.expect_urlopen('https://twitter.com/i/activity/favorited_popup?id=100',
json.dumps({'htmlUsers': as_twitter_test.FAVORITES_HTML}))
self.mox.ReplayAll()
tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
self.assert_equals(as_twitter_test.LIKES_FROM_HTML[0],
tw.get_like('unused', '100', '353'))
示例11: setUp
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def setUp(self):
super(TwitterTest, self).setUp()
oauth_dropins.appengine_config.TWITTER_APP_KEY = 'my_app_key'
oauth_dropins.appengine_config.TWITTER_APP_SECRET = 'my_app_secret'
self.handler.messages = []
self.auth_entity = oauth_twitter.TwitterAuth(
id='my_string_id',
token_key='my_key', token_secret='my_secret',
user_json=json.dumps({'name': 'Ryan Barrett',
'screen_name': 'snarfed_org',
'description': 'something about me',
'profile_image_url': 'http://pi.ct/ure',
}))
self.auth_entity.put()
self.tw = Twitter.new(self.handler, auth_entity=self.auth_entity)
示例12: test_update_twitter_picture_user_lookup_404s
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import new [as 别名]
def test_update_twitter_picture_user_lookup_404s(self):
auth_entity = oauth_twitter.TwitterAuth(
id='id', token_key='key', token_secret='secret',
user_json=json.dumps({'name': 'Bad',
'screen_name': 'bad',
'profile_image_url': 'http://pi.ct/ure',
}))
auth_entity.put()
source = Twitter.new(None, auth_entity=auth_entity).put()
lookup_url = gr_twitter.API_BASE + cron.TWITTER_API_USER_LOOKUP
self.expect_urlopen(lookup_url % 'bad', status=404)
self.mox.ReplayAll()
resp = cron.application.get_response('/cron/update_twitter_pictures')
self.assertEqual(200, resp.status_int)
self.assertEquals('http://pi.ct/ure', source.get().picture)