def __init__(self, **kwargs): self.client = TumblrRestClient(**kwargs) self.dummy = { 'likes': {'liked_posts': []}, 'following': {'blogs': []}, 'posts': {'total_posts': 0, 'posts': []} }
def tumblrAuth(config, OAUTH_TUMBLR): consumer_key = config.get("tumblr", "consumer_key") consumer_secret = config.get("tumblr", "secret_key") hostname = config.get("tumblr", "blog") try: f = open(OAUTH_TUMBLR, "rb") oauth_token = pickle.load(f) f.close() except: print "Couldn't open %s, reloading..." % OAUTH_TUMBLR oauth_token = False if (not oauth_token): tumblr_oauth = TumblrOAuthClient(consumer_key, consumer_secret) authorize_url = tumblr_oauth.get_authorize_url() print "Visit: %s" % authorize_url oauth_verifier = raw_input('What is the oauth_verifier?') oauth_token = tumblr_oauth.get_access_token(oauth_verifier) print "Access key:", oauth_token.key print "Access Secret:", oauth_token.secret f = open(OAUTH_TUMBLR, "w") pickle.dump(oauth_token, f) f.close() f = open(TIMECACHE, "rb") lasttime = f.read(128) f.close() return TumblrRestClient(consumer_key, consumer_secret, oauth_token.key, oauth_token.secret)
def __init__(self, conf): self.log = getLogger(__name__) self.conf = conf self.__info = None self.client = TumblrRestClient(self.conf.tumblr_consumer_key, self.conf.tumblr_consumer_secret, self.conf.tumblr_oauth_token, self.conf.tumblr_oauth_secret) self.log.debug('%s init done', __name__)
def getResource(filter='photo', resKey="photos"): client = TumblrRestClient(API_KEY) _thArr = [] for url in TURL: print "start Spider-URL:%s" % url _thread = Thread(target=getData, args=[client, url, filter, resKey]) _thread.start() _thArr.append(_thread) for th in _thArr: th.join() print "all Spider finish ..."
def pull_tumblr(post_id): client = TumblrRestClient( 'q3K5ba44O1DLAv39TDsp4fEMNY1pGAdXsiciIQQqZdAsXF54Zt', 'UnkAeG6I7PRHidVqikB3zcrL6DI94q0woJv5sIeUCj3B7ndCdJ', 'KT75Gar86W3elQAuU7VyiT9UUstfX6JAFGTvG01pJYKStqlAXN', 'ZggEOt83VSC2lzvN01SWmFJy98r13oeuWyciXxfxVqOwAvo81n' ) # print client.info() tumblr_post = client.posts('cfsacompetition.tumblr.com', type='text', id=post_id) return tumblr_post
def __init__(self, *args): self.api = TumblrRestClient(tumblrLogin["consumerkey"], tumblrLogin["consumersecret"], tumblrLogin["oauthtoken"], tumblrLogin["oauthtokensecret"]) self.clientInfo = self.api.info() self.blogs = self.clientInfo['user']['blogs'] for arg in args: if arg.find("http", 0, len(arg)) != -1: self.blog = self.findBlog(arg, True) else: self.blog = self.findBlog(arg, False) self.queue = [] self.batch = [] self.state = "draft" self.number = 0 self.name = ""
def getFollowings(): _retVal = [] client = TumblrRestClient(API_KEY, SECRTY_KEY, TOKEN_KEY, TOKEN_SECRTY) _followings = client.following(limit=1) if "meta" in _followings: print "Server Return ERROR : %s,code :%s" % (_followings["msg"], _followings["status"]) return # 先确定总关注数 _total = _followings["total_blogs"] _flBlogArr = [] for offset in xrange(0, _total / 20 + 1): _followings = client.following(limit=20, offset=offset * 20) for ele in _followings["blogs"]: _flBlogArr.append(ele["uuid"]) _retVal = _flBlogArr return _retVal
def __init__(self, consumer_key: str, consumer_secret: str, oauth_token: str, oauth_secret: str): """ Summary: Initializes and instance of TumblrClient Args: consumer_key: a valid tumblr rest api application's consumer key consumer_secret: a valid tumblr rest api application's consumer secret oauth_token: a valid tumblr rest api application's oauth token oauth_secret: a valid tumblr rest api application's oauth_secret Returns: An instance of the TumblrClient class """ self.tumblr = TumblrRestClient( consumer_key = consumer_key, consumer_secret = consumer_secret, oauth_token = oauth_token, oauth_secret = oauth_secret )
def __init__(self, token=None, **kwargs): """ :param token: :param kwargs: """ super(ServiceTumblr, self).__init__(token, **kwargs) self.AUTH_URL = 'https://www.tumblr.com/oauth/authorize' self.ACC_TOKEN = 'https://www.tumblr.com/oauth/access_token' self.REQ_TOKEN = 'https://www.tumblr.com/oauth/request_token' self.consumer_key = settings.TH_TUMBLR_KEY['consumer_key'] self.consumer_secret = settings.TH_TUMBLR_KEY['consumer_secret'] self.token = token self.service = 'ServiceTumblr' self.oauth = 'oauth1' if self.token is not None: token_key, token_secret = self.token.split('#TH#') self.tumblr = TumblrRestClient(self.consumer_key, self.consumer_secret, token_key, token_secret)
import string import time from datetime import datetime from urlparse import parse_qs from django.conf import settings from django.shortcuts import render from instagram.client import InstagramAPI from apps.worker.models import GoogleImages from pytumblr import TumblrRestClient # creating client for tumbler tumblr_client = TumblrRestClient(consumer_key=settings.TUMBLR_KEY, consumer_secret=settings.TUMBLR_SECRET) # creating client for instagram inst_client = InstagramAPI(client_id=settings.INSTAGRAM_ID) def make_token(L = 10): return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(L)) def index(request): return render(request, 'index.html', {}) def google(request):
#Tumblr API import os from mimetypes import guess_type from __init__ import tumblrLogin from tumblpy import Tumblpy import tumblr_photoset_upload api = Tumblpy(tumblrLogin["consumerkey"] , tumblrLogin["consumersecret"], tumblrLogin["oauthtoken"], tumblrLogin["oauthtokensecret"]) from pytumblr import TumblrRestClient api = TumblrRestClient(tumblrLogin["consumerkey"] , tumblrLogin["consumersecret"], tumblrLogin["oauthtoken"], tumblrLogin["oauthtokensecret"]) blog_url = api.info() print(blog_url) blogName = blog_url['user']['blogs'][0]['name'] def posts(directory, caption, tags, state): print ("Posting to: " + blog_url) photo = open(directory, 'rb') params = {'type':'photo', 'caption': caption, 'data': [photo, photo], 'state': state, 'tags': tags} post = api.post('post', blog_url=blog_url, params=params) print ("Post ID: " + str(post['id'])) # returns id if posted successfully #Creates a photo post using a source URL api.create_photo(blogName, state="draft", tags=["testing", "ok"],
from pytumblr import TumblrRestClient import json from bs4 import BeautifulSoup from random import choice client = TumblrRestClient('9g1lRa75IJ7HLbnyqMCaXsSsnvyz8uUsa7ZLzyGCipFciA23PM') def tumblrSelection(category): storyposts = posts(tag=category) #storyposts = [{'body': '<p><a href="https://en.wikipedia.org/wiki/Universe">https://en.wikipedia.org/wiki/Universe</a></p><p>No, literally.</p><p>As Douglas Adams said, the universe is big. Really big</p>', 'short_url': 'https://tmblr.co/ZJc03i22P_y9r', 'tags': ['passion'], 'title': 'Astronomical Numbers', 'plain': 'https://en.wikipedia.org/wiki/UniverseNo, literally.As Douglas Adams said, the universe is big. Really big', 'date': '2016-02-26 10:38:48 GMT', 'img_url': None, 'link_url': '<a href="https://en.wikipedia.org/wiki/Universe">https://en.wikipedia.org/wiki/Universe</a>', 'post_url': 'http://itabn.tumblr.com/post/140022366837/astronomical-numbers'}, {'body': '<p><a href="https://en.wikipedia.org/wiki/Number">https://en.wikipedia.org/wiki/Number</a></p><p>It starts with counting: 1, 2, 3 are what the maths guys call the Natural Numbers. From there it gets more and more UN-natural, all the way to imaginary and beyond, to some very weird structures that still get called numbers.</p>', 'short_url': 'https://tmblr.co/ZJc03i22P_oKs', 'tags': ['passion'], 'title': 'You Call That a Number?', 'plain': 'https://en.wikipedia.org/wiki/NumberIt starts with counting: 1, 2, 3 are what the maths guys call the Natural Numbers. From there it gets more and more UN-natural, all the way to imaginary and beyond, to some very weird structures that still get called numbers.', 'date': '2016-02-26 10:37:01 GMT', 'img_url': None, 'link_url': '<a href="https://en.wikipedia.org/wiki/Number">https://en.wikipedia.org/wiki/Number</a>', 'post_url': 'http://itabn.tumblr.com/post/140022326582/you-call-that-a-number'}] stories = {} if storyposts: featureStory = storyposts[0] else: featureStory = None #todo handle zero stories feature_candidates = [] for post in storyposts: if post["featured"]: feature_candidates.append(post) featureStory = choice(feature_candidates) stories["featured"] = featureStory if featureStory: storyposts.remove(featureStory) stories["other"] = storyposts return stories def posts(**kwargs):
from pytumblr import TumblrRestClient from xml.dom import minidom from os.path import join import time import os if __name__ == "__main__": DATA_DIR = "data" TAGS = ["#selfie", "selfie"] keyDoc = minidom.parse('keys.xml') keys = {} for i in keyDoc.getElementsByTagName('string'): keys[i.attributes['name'].value] = i.childNodes[0].data mTumblr = TumblrRestClient(keys['consumer_key'], keys['consumer_secret'], keys['oauth_token'], keys['oauth_token_secret']) for directory in [ d for d in os.listdir(DATA_DIR) if os.path.isdir(join(DATA_DIR, d)) ]: for filename in [ f for f in os.listdir(join(DATA_DIR, directory)) if f.startswith("memememeselfie") and f.endswith(".jpg") ]: fullPath = join(DATA_DIR, directory, filename) print "POSTING %s" % fullPath mTumblr.create_photo(directory, state="published", tags=TAGS, data=fullPath) time.sleep(1)