本文整理汇总了Python中tumblr.Tumblr类的典型用法代码示例。如果您正苦于以下问题:Python Tumblr类的具体用法?Python Tumblr怎么用?Python Tumblr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tumblr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_verify_without_disqus
def test_verify_without_disqus(self):
self.expect_webmention_requests_get('http://primary/', 'no disqus here!',
verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertIsNone(t.disqus_shortname)
示例2: test_new
def test_new(self):
t = Tumblr.new(self.handler, auth_entity=self.auth_entity)
self.assertEquals(self.auth_entity.key, t.auth_entity)
self.assertEquals('name', t.name)
self.assertEquals(['http://primary/'], t.domain_urls)
self.assertEquals(['primary'], t.domains)
self.assertEquals('http://api.tumblr.com/v2/blog/primary/avatar/512', t.picture)
示例3: _test_verify_finds_disqus
def _test_verify_finds_disqus(self, snippet):
# this requests.get is called by webmention-tools
self.expect_requests_get(
'http://primary/', '<html>\nstuff\n%s\n</html>' % snippet, verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertEquals('my-disqus-name', t.disqus_shortname)
示例4: test_new_with_blog_name
def test_new_with_blog_name(self):
self.auth_entity.user_json = json.dumps({
'user': {'blogs': [{'url': 'foo'},
{'name': 'bar', 'url': 'baz'},
{'name': 'biff', 'url': 'http://boff/'},
]}})
got = Tumblr.new(self.handler, auth_entity=self.auth_entity, blog_name='biff')
self.assertEquals(['http://boff/'], got.domain_urls)
self.assertEquals(['boff'], got.domains)
示例5: setUp
def setUp(self):
super(TumblrTest, self).setUp()
self.auth_entity = TumblrAuth(id='name', user_json=json.dumps({
'user': {'blogs': [{'url': 'other'},
{'url': 'http://primary/', 'primary': True}]}}))
self.tumblr = Tumblr(id='my id', disqus_shortname='my-disqus-name')
appengine_config.DISQUS_API_KEY = 'my key'
appengine_config.DISQUS_API_SECRET = 'my secret'
appengine_config.DISQUS_ACCESS_TOKEN = 'my token'
示例6: test_verify
def test_verify(self):
# based on http://snarfed.tumblr.com/
# this requests.get is called by webmention-tools
self.expect_requests_get('http://primary/', """
<html><body>
some stuff
<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/my-disqus-name/get_num_replies.js?url131=...&"></script>
</body></html>""", verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertEquals('my-disqus-name', t.disqus_shortname)
示例7: TumblrTest
class TumblrTest(testutil.HandlerTest):
def setUp(self):
super(TumblrTest, self).setUp()
self.auth_entity = TumblrAuth(id='name', user_json=json.dumps({
'user': {'blogs': [{'url': 'other'},
{'url': 'http://primary/', 'primary': True}]}}))
self.tumblr = Tumblr(disqus_shortname='my-disqus-name')
appengine_config.DISQUS_API_KEY = 'my key'
appengine_config.DISQUS_API_SECRET = 'my secret'
appengine_config.DISQUS_ACCESS_TOKEN = 'my token'
def disqus_params(self, params):
params.update({
'api_key': 'my key',
'api_secret': 'my secret',
'access_token': 'my token',
})
return params
def expect_thread_details(self, resp=None, **kwargs):
if resp is None:
resp = {'response': {'id': '87654'}}
self.expect_requests_get(
tumblr.DISQUS_API_THREAD_DETAILS_URL,
json.dumps(resp),
params=self.disqus_params({'forum': 'my-disqus-name',
'thread':'link:http://primary/post/123999'}),
**kwargs)
def test_new(self):
t = Tumblr.new(self.handler, auth_entity=self.auth_entity)
self.assertEquals(self.auth_entity.key, t.auth_entity)
self.assertEquals('name', t.name)
self.assertEquals(['http://primary/'], t.domain_urls)
self.assertEquals(['primary'], t.domains)
self.assertEquals('http://api.tumblr.com/v2/blog/primary/avatar/512', t.picture)
def test_new_no_primary_blog(self):
self.auth_entity.user_json = json.dumps({'user': {'blogs': [{'url': 'foo'}]}})
self.assertIsNone(Tumblr.new(self.handler, auth_entity=self.auth_entity))
self.assertIn('Tumblr blog not found', next(iter(self.handler.messages)))
def test_new_with_blog_name(self):
self.auth_entity.user_json = json.dumps({
'user': {'blogs': [{'url': 'foo'},
{'name': 'bar', 'url': 'baz'},
{'name': 'biff', 'url': 'http://boff/'},
]}})
got = Tumblr.new(self.handler, auth_entity=self.auth_entity, blog_name='biff')
self.assertEquals(['http://boff/'], got.domain_urls)
self.assertEquals(['boff'], got.domains)
def test_verify(self):
# based on http://snarfed.tumblr.com/
# this requests.get is called by webmention-tools
self.expect_requests_get('http://primary/', """
<html><body>
some stuff
<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/my-disqus-name/get_num_replies.js?url131=...&"></script>
</body></html>""", verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertEquals('my-disqus-name', t.disqus_shortname)
def test_verify_without_disqus(self):
self.expect_requests_get('http://primary/', 'no disqus here!', verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertIsNone(t.disqus_shortname)
def test_create_comment(self):
self.expect_thread_details()
self.expect_requests_post(
tumblr.DISQUS_API_CREATE_POST_URL,
json.dumps({'response': {'ok': 'sgtm'}}),
params=self.disqus_params({
'thread': '87654',
'message': '<a href="http://who">who</a>: foo bar'}))
self.mox.ReplayAll()
resp = self.tumblr.create_comment('http://primary/post/123999/xyz_abc?asdf',
'who', 'http://who', 'foo bar')
self.assertEquals({'ok': 'sgtm'}, resp)
def test_create_comment_with_unicode_chars(self):
self.expect_thread_details()
self.expect_requests_post(
tumblr.DISQUS_API_CREATE_POST_URL,
json.dumps({}),
params=self.disqus_params({
'thread': '87654',
'message': '<a href="http://who">Degenève</a>: foo Degenève bar'}))
self.mox.ReplayAll()
resp = self.tumblr.create_comment('http://primary/post/123999/xyz_abc',
u'Degenève', 'http://who', u'foo Degenève bar')
示例8: template_vars
def template_vars(self):
if not self.source:
return {}
vars = super(UserHandler, self).template_vars()
vars.update({
'source': self.source,
'epoch': util.EPOCH,
})
# Blog webmention promos
if 'webmention' not in self.source.features:
if self.source.SHORT_NAME in ('blogger', 'tumblr', 'wordpress'):
vars[self.source.SHORT_NAME + '_promo'] = True
else:
for domain in self.source.domains:
if ('.blogspot.' in domain and # Blogger uses country TLDs
not Blogger.query(Blogger.domains == domain).get()):
vars['blogger_promo'] = True
elif (domain.endswith('tumblr.com') and
not Tumblr.query(Tumblr.domains == domain).get()):
vars['tumblr_promo'] = True
elif (domain.endswith('wordpress.com') and
not WordPress.query(WordPress.domains == domain).get()):
vars['wordpress_promo'] = True
# Responses
if 'listen' in self.source.features:
vars['responses'] = []
for i, r in enumerate(Response.query()
.filter(Response.source == self.source.key)\
.order(-Response.updated)):
r.response = json.loads(r.response_json)
if r.activity_json: # handle old entities
r.activities_json.append(r.activity_json)
r.activities = [json.loads(a) for a in r.activities_json]
if (not gr_source.Source.is_public(r.response) or
not all(gr_source.Source.is_public(a) for a in r.activities)):
continue
r.actor = r.response.get('author') or r.response.get('actor', {})
if not r.response.get('content'):
phrases = {
'like': 'liked this',
'repost': 'reposted this',
'rsvp-yes': 'is attending',
'rsvp-no': 'is not attending',
'rsvp-maybe': 'might attend',
'invite': 'is invited',
}
r.response['content'] = '%s %s.' % (
r.actor.get('displayName') or '',
phrases.get(r.type) or phrases.get(r.response.get('verb')))
# convert image URL to https if we're serving over SSL
image_url = r.actor.setdefault('image', {}).get('url')
if image_url:
r.actor['image']['url'] = util.update_scheme(image_url, self)
# generate original post links
r.links = self.process_webmention_links(r)
vars['responses'].append(r)
if len(vars['responses']) >= 10 or i > 200:
break
# Publishes
if 'publish' in self.source.features:
publishes = Publish.query().filter(Publish.source == self.source.key)\
.order(-Publish.updated)\
.fetch(10)
for p in publishes:
p.pretty_page = util.pretty_link(
p.key.parent().id(), a_class='original-post', new_tab=True)
vars['publishes'] = publishes
if 'webmention' in self.source.features:
# Blog posts
blogposts = BlogPost.query().filter(BlogPost.source == self.source.key)\
.order(-BlogPost.created)\
.fetch(10)
for b in blogposts:
b.links = self.process_webmention_links(b)
try:
text = b.feed_item.get('title')
except ValueError:
text = None
b.pretty_url = util.pretty_link(b.key.id(), text=text,
a_class='original-post', max_length=40,
new_tab=True)
# Blog webmentions
webmentions = BlogWebmention.query()\
.filter(BlogWebmention.source == self.source.key)\
.order(-BlogWebmention.updated)\
.fetch(10)
for w in webmentions:
w.pretty_source = util.pretty_link(w.source_url(), a_class='original-post',
#.........这里部分代码省略.........
示例9: Tumblr
#coding=utf-8
'''Demo program which uses the live-journal module.'''
import sys
from tumblr import Tumblr
#username='peter4test', password='peter2win'
b = Tumblr('http://peter4test.tumblr.com/', None, '[email protected]', 'peter2win')
if not b.isItMe():
print 'isItMe() False: invalid url'
sys.exit()
if not b.authenticate():
print "Authentication failed"
sys.exit()
print "My available tags:"
for tag in b.getTags():
print tag
print "My available categories:"
for cat in b.getCategories():
print cat
b.setTitle('draft title')
b.setContent('draft content')
# technology exists and was retrieved through getCategories, but
# business doesn't exist so behind the scenes it must be added to
示例10: unpoco
def unpoco():
dl = Tumblr("unpoco")
dl.run()
示例11: labialounge
def labialounge():
dl = Tumblr("labialounge")
dl.run()
示例12: inspireawesome
def inspireawesome():
dl = Tumblr("inspireawesome")
dl.run()
示例13: onehandedtypist
def onehandedtypist():
dl = Tumblr("onehandedtypist")
dl.run()
示例14: backseam
def backseam():
dl = Tumblr("backseam")
dl.run()
示例15: nylonfoxie
def nylonfoxie():
dl = Tumblr("nylonfoxie")
dl.run()