Beispiel #1
0
    def setUp(self):
        hostname = config.TEST_HOSTNAME
        consumer = oauth.Consumer(config.TEST_CONSUMER_KEY,
                                  config.TEST_CONSUMER_SECRET)
        token = oauth.Token(config.TEST_ACCESS_KEY, config.TEST_ACCESS_SECRET)

        self.client = TumblrClient(hostname, consumer, token)
Beispiel #2
0
def main():
    while True:
        print("still true!")
        conn = Connection(
            "mongodb://*****:*****@twumblr-bakanaka-data-0.dotcloud.com:14914"
        )
        coll = conn.db.users
        names = coll.find()
        for sn in names:
            lst = json.loads(
                requests.get(
                    "https://api.twitter.com/1/statuses/user_timeline.json?screen_name="
                    + sn["twitter"]).content)
            if "status" in sn:
                matched = False
                consumer = oauth2.Consumer(
                    "BmyWZMbAzcK9Y7mEQKTgf1JI4icFlXvfxxkfIzuG9nFFVJfg9Q",
                    "p5ohAI2hT7tSwjVCI0HA8oTpOYAvc3m6tIPAXJGNXkur6PgQdT")
                token = oauth2.Token(sn["key"], sn["secret"])
                cli = TumblrClient(sn["hostname"], consumer, token)
                for x in range(19, -1, -1):
                    if not matched:
                        print("not matched")
                        if lst[x]["text"] == sn["status"]:
                            print("matched!")
                            matched = True
                    else:
                        print("f**k yeah")
                        tumble(lst[x]["text"], cli)
            sn["status"] = lst[0]["text"]
            coll.save(sn)
        time.sleep(30)
def main():
    hostname = 'EXAMPLE.tumblr.com'

    consumer_key = 'API_KEY'
    consumer_secret = 'API_SECRET'

    access_key = 'ACCESS_KEY'
    access_secret = 'ACCESS_KEY'

    consumer = oauth.Consumer(consumer_key, consumer_secret)
    token = oauth.Token(access_key, access_secret)

    params = {
        'type': 'quote',
    }

    client = TumblrClient(hostname, consumer, token)
    for post in lister(client, 10, params):
        print post['id']
Beispiel #4
0
def main():
	subdomain = sys.argv[1]

	text = open('text.txt', 'w')
	photo = open('photo.txt', 'w')
	quote = open('quote.txt', 'w')
	link = open('link.txt', 'w')
	chat = open('chat.txt', 'w')
	audio = open('audio.txt', 'w')
	video = open('video.txt', 'w')
	answer = open('answer.txt', 'w')

	bigphoto = open('bigphotos.txt', 'w')

	hostname = subdomain + '.tumblr.com'

	consumer_key = ''
	consumer_secret = ''

	access_key = 'ACCESS_KEY'
	access_secret = 'ACCESS_KEY'

	consumer = oauth.Consumer(consumer_key, consumer_secret)
	token = oauth.Token(access_key, access_secret)

	params = {
#	   'type': 'photo',
	}

	client = TumblrClient(hostname, consumer, token)
	for post in lister(client, params):
		if (not 'source_title' in post) or (post['source_title'] == subdomain):
			eval(post['type']).write(post['post_url'] + '\n')
			print post['type'] + '\t' + post['post_url']
			if (post['type'] == 'photo'):
				for onephoto in post['photos']:
					bigphoto.write(onephoto['original_size']['url'] + '\n')
def main():

    # http://stackoverflow.com/a/539024/315168
    if not os.environ.get("KEY", None):
        sys.exit("Give app key as KEY env")

    if not os.environ.get("SECRET", None):
        sys.exit("Give app key as SECRET env")

    if not os.environ.get("TOKEN", None):
        sys.exit("Give Oauth token as TOKEN env")

    if not os.environ.get("VERIFIER", None):
        sys.exit("Give Oauth verifier as VERIFIER env")

    if not os.environ.get("BLOG", None):
        sys.exit("Give blog URL as BLOG env")

    # Create Tumblr client

    consumer = oauth.Consumer(os.environ["KEY"], os.environ["SECRET"])
    token = oauth.Token(os.environ["TOKEN"], os.environ["VERIFIER"])

    tumblr = TumblrClient(os.environ["BLOG"], consumer, token)

    # path to the directory (relative or absolute)
    dirpath = sys.argv[1] if len(sys.argv) >= 2 else r'.'

    # Read extra photo description injection (the name of the place) from command line
    if len(sys.argv) > 2:
        description_prefix = sys.argv[2].decode("utf-8")
    else:
        description_prefix = None

    if len(sys.argv) > 3:
        tags = sys.argv[3]
    else:
        tags = None

    index = Index(dirpath)

    # get all entries in the directory w/ stats
    entries = (os.path.join(dirpath, fn) for fn in os.listdir(dirpath))
    entries = ((os.stat(path), path) for path in entries)
    entries = list(entries)
    
    # For sorting keys see os.stat https://docs.python.org/2/library/os.html#os.stat
    for stats, path in sorted(entries, key=lambda entry: entry[0].st_mtime):
        root, ext = os.path.splitext(path)
        if ext.lower() not in [".jpg", ".jpeg"]:
            # Only consider images
            continue

        # XXX: Currently Tumblr does not have separate title and description
        # for photos.. only for text posts
        title, desc = get_photo_title_and_description(path)

        if description_prefix:
            desc = u"<em>%s.</em> %s" % (description_prefix, desc)

        if not index.is_already_posted(path):
            print "Posting %s: %s" % (path.encode("utf-8"), desc.encode("utf-8"))
            try:
                response = tumblr.create_photo_post(path, request_params={"caption": desc, "tags": tags})
            except HTTPError, e:
                # Some verbosity what the fusck is going on
                # Usually '{"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":["Oh no! You\'ve reached your photo upload limit for today. Please come again tomorrow!"]}}'
                print e.read()
                raise e

            response = json.loads(response)
            if response["meta"]["status"] != 201:
                print response
                raise RuntimeError("Tumbrl unsuccesful")

            tumblr_id = response["response"]["id"]
            index.update(path, tumblr_id)
            index.save()
        else:
            print "Already posted %s" % path.encode("utf-8")
Beispiel #6
0
def main():

    # http://stackoverflow.com/a/539024/315168
    if not os.environ.get("KEY", None):
        sys.exit("Give app key as KEY env")

    if not os.environ.get("SECRET", None):
        sys.exit("Give app key as SECRET env")

    if not os.environ.get("TOKEN", None):
        sys.exit("Give Oauth token as TOKEN env")

    if not os.environ.get("VERIFIER", None):
        sys.exit("Give Oauth verifier as VERIFIER env")

    if not os.environ.get("BLOG", None):
        sys.exit("Give blog URL as BLOG env")

    # Create Tumblr client

    consumer = oauth.Consumer(os.environ["KEY"], os.environ["SECRET"])
    token = oauth.Token(os.environ["TOKEN"], os.environ["VERIFIER"])

    tumblr = TumblrClient(os.environ["BLOG"], consumer, token)

    # path to the directory (relative or absolute)
    dirpath = sys.argv[1] if len(sys.argv) >= 2 else r'.'

    # Read extra photo description injection (the name of the place) from command line
    if len(sys.argv) > 2:
        description_prefix = sys.argv[2].decode("utf-8")
    else:
        description_prefix = None

    if len(sys.argv) > 3:
        tags = sys.argv[3]
    else:
        tags = None

    index = Index(dirpath)

    # get all entries in the directory w/ stats
    entries = (os.path.join(dirpath, fn) for fn in os.listdir(dirpath))
    entries = ((os.stat(path), path) for path in entries)
    entries = list(entries)
    entries.sort()

    for mdate, path in sorted(entries):
        root, ext = os.path.splitext(path)
        if ext.lower() not in [".jpg", ".jpeg"]:
            # Only consider images
            continue

        # XXX: Currently Tumblr does not have separate title and description
        # for photos.. only for text posts
        title, desc = get_photo_title_and_description(path)

        if description_prefix:
            desc = u"<em>%s.</em> %s" % (description_prefix, desc)

        if not index.is_already_posted(path):
            print "Posting %s: %s" % (path.encode("utf-8"),
                                      desc.encode("utf-8"))
            try:
                response = tumblr.create_photo_post(path,
                                                    request_params={
                                                        "caption": desc,
                                                        "tags": tags
                                                    })
            except HTTPError, e:
                # Some verbosity what the fusck is going on
                # Usually '{"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":["Oh no! You\'ve reached your photo upload limit for today. Please come again tomorrow!"]}}'
                print e.read()
                raise e

            response = json.loads(response)
            if response["meta"]["status"] != 201:
                print response
                raise RuntimeError("Tumbrl unsuccesful")

            tumblr_id = response["response"]["id"]
            index.update(path, tumblr_id)
            index.save()
        else:
            print "Already posted %s" % path.encode("utf-8")
 def setupAPI(self):
   hostname = self.publishURL
   consumer = oauth.Consumer(self.api_key, self.api_secret)
   token = oauth.Token(self.final_oauth_token, self.final_oauth_token_secret)
   self.tumblr = TumblrClient(hostname, consumer, token) 
class TumblrObject(OAuthObjectBase):
  def __init__(self):
    OAuthObjectBase.__init__(self)
    self.apiName = "tumblr"

  def authPart1(self):
    from tumblr.oauth import TumblrOAuthClient
    self.tumblr_oauth = TumblrOAuthClient(self.api_key, self.api_secret)

    auth_url = self.tumblr_oauth.get_authorize_url()

    return auth_url

  def authPart2(self, oauth_verifier):
    access_token = self.tumblr_oauth.get_access_token(oauth_verifier)

    print "Access key:", access_token.key
    print "Access Secret:", access_token.secret

    self.final_oauth_token = access_token.key
    self.final_oauth_token_secret = access_token.secret

    authDict = authPickler.getAuthDict(self.apiName)
    authDict["final_oauth_token"] = self.final_oauth_token
    authDict["final_oauth_token_secret"] = self.final_oauth_token_secret
    authPickler.setAuthDict(self.apiName, authDict)
    self.authorised = True

    self.setupAPI()

    return redirectToUrlText(web.ctx.homedomain)

  def setupAPI(self):
    hostname = self.publishURL
    consumer = oauth.Consumer(self.api_key, self.api_secret)
    token = oauth.Token(self.final_oauth_token, self.final_oauth_token_secret)
    self.tumblr = TumblrClient(hostname, consumer, token) 


  def postTestPost(self):
    params = {
      'type': 'text',
      'body': 'testPost'
    }
    json_response = self.tumblr.create_post(request_params=params)
    if json_response["meta"]["status"] != 201:
      raise Exception("Tumblr upload error!")   
    
  def postImagePost(self, jobDict):
    captionString = ""
    
    if jobDict["title"] != None:
      captionString = "<strong>" + jobDict["title"] + "</strong><br/>"
    if jobDict["description"] != None:
      captionString += jobDict["description"]
      
    params = {
        'type':'photo',
        'caption': captionString,
        'link': jobDict["flickrurl"],
        'source': jobDict["flickrImageLargeUrl"],
        'tags': ','.join(jobDict["tags"])
    }
        
    json_response = self.tumblr.create_post(request_params=params)
    if json_response["meta"]["status"] != 201:
      print "TUMBLR ERROR"
      print json_response
      raise Exception("Tumblr upload error!")