本文整理汇总了Python中tumblr.Api类的典型用法代码示例。如果您正苦于以下问题:Python Api类的具体用法?Python Api怎么用?Python Api使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Api类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: image_posts_with_tags
def image_posts_with_tags(blogname):
'''
given the url for a blog, returns a list of all the Image posts that have tags.
'''
api = Api(blogname)
imgPosts = api.read(type='photo')
return filter(lambda x: 'tags' in x, imgPosts)
开发者ID:mdocode,项目名称:hangTumblr,代码行数:7,代码来源:hangblogs.py
示例2: post_to_tumblr
def post_to_tumblr(self, title, url):
api = Api(BLOG, USER, PASSWORD)
try:
html = '<img src="%s" alt="%s" />' % (url, title)
api.write_regular(title, html)
except TumblrError, e:
logging.error(e)
开发者ID:calle,项目名称:fn,代码行数:7,代码来源:upload.py
示例3: testBadAuthenticate
def testBadAuthenticate(self):
api = Api(BLOG, USER, 'badpassword' )
try:
api.auth_check()
assert False # should never get here
except TumblrAuthError, e:
pass
开发者ID:mdocode,项目名称:hangTumblr,代码行数:7,代码来源:tumblr-test.py
示例4: populate_models
def populate_models(self):
'''
Import tumblr entries for the defined user in settings
'''
tumblr_settings = {
'tumblr_user':settings.TUMBLR_USER_NAME,
'email':settings.TUMBLR_USER_EMAIL,
'password':settings.TUMBLR_USER_PASSWORD
}
if tumblr_settings['email'] != '' and tumblr_settings['password'] != '':
self.log.info('email/pwd specified - attempting Authenticated read')
tumblr_api = Api(name=tumblr_settings['tumblr_user'], email=tumblr_settings['email'], password=tumblr_settings['password'])
tumbls = tumblr_api.authenticated_read(type=self.type)
else:
self.log.info('email/pwd *NOT* specified - attempting unauthenticated read')
tumblr_api = Api(tumblr_settings['tumblr_user'])
tumbls = tumblr_api.read(type=self.type)
for tumbl in tumbls:
self.log.debug(tumbl['type'])
self.log.debug(tumbl['id'])
self.log.debug(datetime.datetime.strptime(tumbl['date-gmt'], '%Y-%m-%d %H:%M:%S %Z'))
if tumbl['type'] == 'regular':
self.log.debug(tumbl['regular-title'])
self.log.debug('--'*10)
# use the class method to triage content-types
TumbleItem.create_new_item(tumbl['type'], tumbl)
self.log.info('import complete')
开发者ID:mgan59,项目名称:django-tumblr,代码行数:30,代码来源:sync_tumblr.py
示例5: force_update
def force_update(self, request, tumblr_queryset):
'''
Force an update of the tumblr item, including it's tags by deleting the item
and creating a new one from the tumblrapi as data-source. function iterates
over query_set and can handle multiple checked items.
*note:
Design decision was made to use delete then create, as opposed to an standard
update because of tags. In order to do a pure update method this could be refactored
to overload(set) the model data_fields with data from api and then call .clear() on the tag
field and then manually add the tags again. Or reconcile tags manually using remove/add
Could be performance implications between write/delete vs. update. Though all calls
to foreign-key on tags will result in write/delete.
Additionally, this causes the id field on all sub-content-modals to increment, could cause
integration issues with those that want static urls based on django id. this DOESNT change
the tumblr_id however.
'''
## There is only one user now
tumblr_user_name = settings.TUMBLR_USER_NAME
tumbl_api = Api(tumblr_user_name + ".tumblr.com")
for qs_object in tumblr_queryset:
update_id = qs_object.tumblr_id
tumbl_item = tumbl_api.read(id=update_id)
## ensure we have the new tumblr item data, and any additional verification
## then delete the old to make room to create the new
qs_object.delete()
# use the class method to triage content-types
TumbleItem.create_new_item(tumbl_item['type'], tumbl_item)
开发者ID:mgan59,项目名称:django-tumblr,代码行数:32,代码来源:admin.py
示例6: main
def main():
if len(sys.argv) != 2:
print "Usage: ./totumblr.py <photofile>"
sys.exit(-1)
photo_filename = sys.argv[1]
parts = photo_filename.split('.')
file_extension = parts[1]
ftp = FTP('www.fakemachine.com')
ftp.login('[email protected]','password')
ftp.cwd('/domains/fakemachine.com/html/tumblrimages/')
text = ftp.retrlines('list')
m = re.search('\d+ matches', text)
match = m.group(0)
parts = match.split(' ')
file_number = int(parts[0]) + 1
remote_filename = "%d.%s" % (file_number,file_extension)
fp = open(photo_filename,'rb')
ftp.storbinary('STOR %s' % remote_filename, fp) # Send the file
fp.close()
ftp.quit()
image_url = "http://www.fakemachine.com/tumblrimages/%s" % remote_filename
api = Api(BLOG,USER,PASSWORD)
post = api.write_photo(source=image_url)
print "Published: ", post['url']
开发者ID:candersonmiller,项目名称:recreational,代码行数:32,代码来源:totumblr.py
示例7: tumblr_text
def tumblr_text(request):
conversation_id = request.POST['conversation_id']
title = request.POST['title']
body = request.POST['body']
# create a dictionary mapping names to random strings so they are unrecognizable but consistent
replacements = generate_replacements()
# strip credit card numbers
credit_pattern = re.compile(r"\d{3,5}\D*\d{3,5}\D*\d{3,5}\D*\d{3,5}")
body = credit_pattern.sub("XXXX-XXXX-XXXX-XXXX", body)
# strip phone numbers
phone_pattern = re.compile(r"(\d{3}\D*)?(\d{3})\D*(\d{4})")
body = phone_pattern.sub("XXX-XXXX", body)
# strip names
#TODO: make sure names.txt is in correct directory relative to server
names_path = os.path.dirname(__file__) + '/../names.txt'
names = open(names_path, 'r')
for name in names:
name = name.rstrip() # remove newline
name_pattern = re.compile(r"\b" + name + r"\b", re.IGNORECASE)
body = name_pattern.sub(replacements[name], body)
tumblr = Api(BLOG,USER,PASSWORD)
post = tumblr.write_regular(title, body)
return HttpResponse(title + "\n" + body)
开发者ID:mponizil,项目名称:LoCreep,代码行数:29,代码来源:util.py
示例8: send_message
def send_message(message):
blog = settings.get('tumblr', 'blog')
email = settings.get('tumblr', 'email')
password = settings.get('tumblr', 'password')
api = Api(blog, email, password)
post = api.write_regular(title=None, body=message)
print post['url']
开发者ID:cataska,项目名称:tweetplurk,代码行数:7,代码来源:mytumblr.py
示例9: read_blogs
def read_blogs(blogs, download_dir):
global config
# Check if the download dir exists; if not create it
if not os.path.exists(download_dir):
os.mkdir(download_dir)
# Process all given blogs
for blog in blogs:
# Check if the target dir exists; if not create it
target_dir = os.path.join(download_dir, blog)
if not os.path.exists(target_dir):
os.mkdir(target_dir)
print "Downloading images from " + blog + " to " + target_dir + "..."
try:
site_url = blog
api = Api(site_url)
posts = api.read(start=0, max=config.max_number_of_images)
#posts = api.read(start=0)
except:
print "error"
imageCounter = 1
for post in posts:
try:
url = post['photo-url-1280']
photo_caption = post['photo-caption']
slug = post['slug']
post_date_str = post['date-gmt']
except:
print "error"
image_name = url.rsplit('/', 1)[1]
# Check if a file extension is given
supported_file_types = ['jpg', 'jpeg', 'png', 'gif']
if not image_name[-3:] in supported_file_types:
# Add an extension to the image name
image_name = image_name + ".jpg"
image_file_name = blog + "_-_" + image_name
target_file_name = os.path.join(target_dir, image_file_name)
# Check if file already exists
if os.path.exists(target_file_name):
print "Image already exists."
imageCounter += 1
continue
if imageCounter > config.max_number_of_images:
break
print "Downloading image Nr " + str(imageCounter) + ": \"" + image_file_name + "\" ..."
download_image(url, target_file_name)
imageCounter += 1
开发者ID:hypebeast,项目名称:yatir,代码行数:55,代码来源:yatir.py
示例10: blog
def blog(request):
"""
Blog page.
Returns the embedded tumblr page.
"""
BLOG = 'jpglab.tumblr.com'
api = Api(BLOG)
post_list = api.read()
return render_to_response('blog.html', RequestContext(request))
开发者ID:jpglab,项目名称:adamglab.com,代码行数:11,代码来源:views.py
示例11: testFixNames
def testFixNames(self):
api = Api(BLOG)
before = {}
before['test_one'] = 1
before['test_two'] = 1
after = api._fixnames(before)
assert not 'test_one' in after
assert 'test-one' in after
assert 'test-two' in after
assert not 'test_two' in after
开发者ID:mdocode,项目名称:hangTumblr,代码行数:12,代码来源:tumblr-test.py
示例12: testEdit
def testEdit(self):
api = Api(BLOG, USER, PASSWORD)
newpost = api.write_regular('title','body')
np = {}
np['post-id'] = newpost['id']
np['regular-body'] = 'edited body'
editedpost = api.write_regular(np)
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(newpost)
assert editedpost['regular-body'] == 'body'
开发者ID:abhiomkar,项目名称:python-tumblr,代码行数:13,代码来源:tumblr-test.py
示例13: handle
def handle(self, *args, **options):
tumblr_model = get_model('djumblr', 'Tumblr')
tumblr_name = 'diegueus9'
tumblr_email = '[email protected]'
print 'working...'
tumblr_api = Api(tumblr_name, tumblr_email,
getpass.getpass('Your tumblr password:'))
t, created = tumblr_model.objects.get_or_create(
name=tumblr_name, email=tumblr_email)
tumblr_response = tumblr_api.read()
for post in tumblr_response:
_(post)
开发者ID:diegueus9,项目名称:djumblr,代码行数:14,代码来源:import_tumblr_blog.py
示例14: taglist
def taglist(username):
api = Api(username)
posts = api.read()
alltags = {}
for post in posts:
tags = post.get('tags', [])
for tag in tags:
try:
alltags[tag][0] += 1
except KeyError:
alltags[tag] = [1, post.get('date-gmt', '')]
taglist = [tuple(val+[tag]) for tag,val in alltags.items()]
return sorted(taglist, reverse=True)
开发者ID:inky,项目名称:tumblr,代码行数:14,代码来源:taglist.py
示例15: testRead
def testRead(self):
api = Api(BLOG)
freq = {}
posts = api.read()
total = 0
for post in posts:
total += 1
type = post['type']
try:
freq[type] += 1
except:
freq[type] = 1
assert total > 0
for type in freq:
assert self.countType(api,type) == freq[type]
开发者ID:mdocode,项目名称:hangTumblr,代码行数:15,代码来源:tumblr-test.py
示例16: LoginController
class LoginController(NSWindowController):
blog = objc.IBOutlet()
password = objc.IBOutlet()
user = objc.IBOutlet()
def init(self):
self.errors = {'403':'Login o password incorrectos','404':'Tumblrlog incorrecto','urlopen':'no ingreso su tumblrlog'}
return self
@objc.IBAction
def authTumblr_(self, sender):
self.p = self.password.stringValue()
self.u = self.user.stringValue()
self.b = self.blog.stringValue()
self.api = Api(self.b, self.u, self.p)
NSLog("Blog %s, User %s , Password %s" % (self.b, self.u, self.p))
try:
self.auth = self.api.auth_check()
self.destroy()
DashboardController.show()
except tumblr.TumblrAuthError:
print self.errors['403']
except tumblr.TumblrError(self):
print self.errors['404']
#except urllib2.HTTPError():
# print self.errors['404']
#except urllib2.URLError:
# print self.errors['urlopen']
def destroy(self):
app = NSApplication.sharedApplication()
appdelegate = app.delegate()
appdelegate.w.close()
开发者ID:jyr,项目名称:opentumblr-cocoa,代码行数:33,代码来源:LoginController.py
示例17: Link
class Link(gui.CeFrame):
def __init__(self, api):
self.api = api
gui.CeFrame.__init__(self, title="Opentumblr CE")
self.l_link = gui.Label(self, "Add a Link", align = "center")
self.l_name = gui.Label(self, "Name (optional)")
self.tc_name = gui.Edit(self)
self.l_url = gui.Label(self, "URL")
self.tc_url = gui.Edit(self)
self.l_description = gui.Label(self, "Description (optional)")
self.tc_description = gui.Edit(self,multiline = True)
self.b_create = gui.Button(self, "Create Post")
self.b_cancel = gui.Button(self, "Cancel")
self.b_create.bind(clicked = self.OnCreateLink)
self.b_cancel.bind(clicked = self.OnCancel)
self.__set_properties()
self.__do_layout()
def __set_properties(self):
pass
def __do_layout(self):
s_link = gui.VBox(border = (5,5,5,5), spacing = 5)
s_link.add(self.l_link)
s_link.add(self.l_name)
s_link.add(self.tc_name)
s_link.add(self.l_url)
s_link.add(self.tc_url)
s_link.add(self.l_description)
s_link.add(self.tc_description)
s_link.add(self.b_create)
s_link.add(self.b_cancel)
self.sizer = s_link
def OnCreateLink(self, evt):
self.name = self.tc_name.get_text()
self.url = self.tc_url.get_text()
self.description = self.tc_description.get_text()
if self.url:
self.api = Api(self.api.name, self.api.email, self.api.password)
try:
self.post = self.api.write_link(self.name, self.url, self.description)
except:
print "Posteado en el primario"
self.close()
else:
gui.Message.ok(title = 'Warning', caption = 'URL is required')
def OnCancel(self, evt):
self.close()
#if __name__ == '__main__':
# app = gui.Application(Link())
# app.run()
开发者ID:jyr,项目名称:opentumblr-ce,代码行数:60,代码来源:link.py
示例18: Chat
class Chat(gui.CeFrame):
def __init__(self, api):
self.api = api
gui.CeFrame.__init__(self, title="Opentumblr CE")
self.l_chat = gui.Label(self, "Add a Chat Post", align="center")
self.l_title = gui.Label(self, "Title (optional)")
self.tc_title = gui.Edit(self)
self.l_dialogue = gui.Label(self, "Dialogue")
self.l_example = gui.Label(self, "Example")
self.l_tourist = gui.Label(self, "Tourist: Could you give us directions to Olive Garden")
self.l_nyorker = gui.Label(
self, "New Yorker: No, but I could give you directions to an actual Italian restaurant."
)
self.tc_dialogue = gui.Edit(self, multiline=True)
self.b_create = gui.Button(self, "Create Post")
self.b_cancel = gui.Button(self, "Cancel")
self.b_create.bind(clicked=self.OnCreateChat)
self.b_cancel.bind(clicked=self.OnCancel)
self.__set_properties()
self.__do_layout()
def __set_properties(self):
pass
def __do_layout(self):
s_chat = gui.VBox(border=(5, 5, 5, 5), spacing=5)
s_chat.add(self.l_chat)
s_chat.add(self.l_title)
s_chat.add(self.tc_title)
s_chat.add(self.l_dialogue)
s_chat.add(self.l_example)
s_chat.add(self.l_tourist)
s_chat.add(self.l_nyorker)
s_chat.add(self.tc_dialogue)
s_chat.add(self.b_create)
s_chat.add(self.b_cancel)
self.sizer = s_chat
def OnCreateChat(self, evt):
self.title = self.tc_title.get_text()
self.conversation = self.tc_dialogue.get_text()
if self.conversation:
self.api = Api(self.api.name, self.api.email, self.api.password)
try:
self.post = self.api.write_conversation(self.title, self.conversation)
except:
print "Posteado en el primario"
self.close()
else:
gui.Message.ok(title="Warning", caption="Dialogue is required")
def OnCancel(self, evt):
self.close()
开发者ID:jyr,项目名称:opentumblr-ce,代码行数:59,代码来源:chat.py
示例19: Quote
class Quote(gui.CeFrame):
def __init__(self, api):
self.api = api
gui.CeFrame.__init__(self, title="Opentumblr CE")
self.l_quote = gui.Label(self, "Add a Quote", align = "center")
self.l_title = gui.Label(self, "Quote")
self.tc_title = gui.Edit(self, multiline = True)
self.l_source = gui.Label(self, "Source (optional)")
self.tc_source = gui.Edit(self,multiline = True)
self.b_create = gui.Button(self, "Create Post")
self.b_cancel = gui.Button(self, "Cancel")
self.b_create.bind(clicked = self.OnCreateQuote)
self.b_cancel.bind(clicked = self.OnCancel)
self.__set_properties()
self.__do_layout()
def __set_properties(self):
pass
def __do_layout(self):
s_quote = gui.VBox(border = (5,5,5,5), spacing = 5)
s_quote.add(self.l_quote)
s_quote.add(self.l_title)
s_quote.add(self.tc_title)
s_quote.add(self.l_source)
s_quote.add(self.tc_source)
s_quote.add(self.b_create)
s_quote.add(self.b_cancel)
self.sizer = s_quote
def OnCreateQuote(self, evt):
self.quote = self.tc_title.get_text()
self.source = self.tc_source.get_text()
if self.quote:
self.api = Api(self.api.name, self.api.email, self.api.password)
try:
self.post = self.api.write_quote(self.quote, self.source)
except:
print "Posteado en el primario"
self.close()
else:
gui.Message.ok(title = 'Warning', caption = 'Quote is required')
def OnCancel(self, evt):
self.close()
#if __name__ == '__main__':
# app = gui.Application(Quote())
# app.run()
开发者ID:jyr,项目名称:opentumblr-ce,代码行数:55,代码来源:quote.py
示例20: Video
class Video(gui.CeFrame):
def __init__(self, api):
self.api = api
gui.CeFrame.__init__(self, title="Opentumblr CE")
self.l_video = gui.Label(self, "Add a Video", align = "center")
self.l_embed = gui.Label(self, "Embed a Video")
self.tc_embed = gui.Edit(self)
self.l_caption = gui.Label(self, "Caption (optional)")
self.tc_caption = gui.Edit(self,multiline = True)
self.b_create = gui.Button(self, "Create Post")
self.b_cancel = gui.Button(self, "Cancel")
self.b_create.bind(clicked = self.OnCreateVideo)
self.b_cancel.bind(clicked = self.OnCancel)
self.__set_properties()
self.__do_layout()
def __set_properties(self):
pass
def __do_layout(self):
s_video = gui.VBox(border = (5,5,5,5), spacing = 2)
s_video.add(self.l_video)
s_video.add(self.l_embed)
s_video.add(self.tc_embed)
s_video.add(self.l_caption)
s_video.add(self.tc_caption)
s_video.add(self.b_create)
s_video.add(self.b_cancel)
self.sizer = s_video
def OnCreateVideo(self, evt):
self.embed = self.tc_embed.get_text()
self.caption = self.tc_caption.get_text()
if self.embed:
self.api = Api(self.api.name, self.api.email, self.api.password)
try:
self.post = self.api.write_video(self.embed, self.caption)
except:
print "Posteado en el primario"
self.close()
else:
gui.Message.ok(title = 'Warning', caption = 'Embed a video is required')
def OnCancel(self, evt):
self.close()
#if __name__ == '__main__':
# app = gui.Application(Video())
# app.run()
开发者ID:jyr,项目名称:opentumblr-ce,代码行数:55,代码来源:video.py
注:本文中的tumblr.Api类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论