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


Python tumblr.Api类代码示例

本文整理汇总了Python中tumblr.Api的典型用法代码示例。如果您正苦于以下问题:Python Api类的具体用法?Python Api怎么用?Python Api使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Api类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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