Skip to content
Create a gist now

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import sys
import os
import os.path
import sqlite3 as lite
import urlparse
import oauth2 as oauth
import urllib
consumer_key = 'your key'
consumer_secret = 'your secret'
oauth_key = 'your other key'
oauth_secret = 'your other secret'
request_token_url = ''
access_token_url = ''
authorize_url = ''
import logging
if __name__ == '__main__':
whoami = os.path.abspath(sys.argv[0])
bindir = os.path.dirname(whoami)
rootdir = os.path.dirname(bindir)
datadir = os.path.join(rootdir, 'data')
datafile = os.path.join(datadir, 'objects.sqlite3')"file %s" % datafile)
# grab top row where it has a description and has NOT been published
con = None
con = lite.connect(datafile)
with con:
cur = con.cursor()
cur.execute("SELECT * FROM objects WHERE description IS NOT NULL AND published IS NULL ORDER BY RANDOM() LIMIT 1")
row = cur.fetchall()
for f in row:
object_id = f[0]
description = f[1]
url = f[2]
published = f[3]
the_body = description + "\n" + "\n" + url
# post to tumblr blog
consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)
resp, content = client.request(request_token_url, "GET")
if resp['status'] != '200':
raise Exception("Invalid response %s." % resp['status'])
request_token = dict(urlparse.parse_qsl(content))
token = oauth.Token(oauth_key, oauth_secret)
client = oauth.Client(consumer, token)
params = {
'type': 'text',
'title': object_id,
'body': the_body,
print client.request("", method="POST", body=urllib.urlencode(params))
with con:
con = con.cursor()
sql = "UPDATE objects SET published = 1 WHERE id=" + str(object_id)
data = cur.fetchone()
print data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.