Пример #1
0
def callback():
	oauth_token = request.args.get('oauth_token')
	oauth_verifier = request.args.get('oauth_verifier')

	# retrieve request token from session
	request_token = session['request_token']
	session.pop('request_token', None)

	token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
	token.set_verifier(oauth_verifier)
	client = oauth.Client(consumer, token)

	resp, content = client.request(access_token_url, "POST")
	access_token = dict(urlparse.parse_qsl(content))
	
	# access resource
	token = oauth.Token(key=access_token['oauth_token'], secret=access_token['oauth_token_secret'])
	client = oauth.Client(consumer, token)
	
	# get user info
	resp, content = client.request("http://api.tumblr.com/v2/user/info", method="GET")
	user_info =  json.loads(content)['response']['user']

	# get db
	db_config = config.getConfig('db')
	db = Mysql(db_config['host'], db_config['user'], db_config['passwd'], db_config['db'], db_config['charset'])
	
	# store access token to db
	sql = "REPLACE INTO authorize VALUES ('%s', '%s', '%s')" % (user_info['name'], access_token['oauth_token'], access_token['oauth_token_secret'])
	db.query(sql)
	
	session['name'] = user_info['name']
	
	return redirect(url_for('index'))
Пример #2
0
#! /usr/bin/env python
#coding=utf-8
import sys   
sys.path.append("..")

from inc.mysql import Mysql
import inc.config as config

db_config = config.getConfig('db')
db = Mysql(db_config['host'], db_config['user'], db_config['passwd'], db_config['db'], db_config['charset'])

# 初始化数据
#db.query("INSERT INTO config (var, value) VALUES ('timeline_last_id', '0')")

# 清空数据
#db.query('TRUNCATE TABLE follows')
#db.query('TRUNCATE TABLE subs')
#db.query('TRUNCATE TABLE url2uid')
#db.query('TRUNCATE TABLE users')
#db.query("UPDATE config SET value='0' WHERE var='timeline_last_id'")