Add debugging method.
This commit is contained in:
parent
ded4b913da
commit
a89a947be5
5
app.py
5
app.py
|
@ -647,6 +647,11 @@ def get_image_detail_with_cache(items, cache_name, thumbwidth=None):
|
||||||
def browse_index():
|
def browse_index():
|
||||||
return render_template('browse_index.html', props=find_more_props)
|
return render_template('browse_index.html', props=find_more_props)
|
||||||
|
|
||||||
|
@app.route('/debug/show_user')
|
||||||
|
def debug_show_user():
|
||||||
|
userinfo = wikidata_oauth.userinfo_call()
|
||||||
|
return '<pre>' + json.dump(userinfo, indent=2) + '</pre>'
|
||||||
|
|
||||||
@app.route('/browse')
|
@app.route('/browse')
|
||||||
def browse_page():
|
def browse_page():
|
||||||
params = get_painting_params()
|
params = get_painting_params()
|
||||||
|
|
|
@ -13,7 +13,7 @@ def api_post_request(params):
|
||||||
resource_owner_secret=session['owner_secret'])
|
resource_owner_secret=session['owner_secret'])
|
||||||
return oauth.post(url, data=params, timeout=4)
|
return oauth.post(url, data=params, timeout=4)
|
||||||
|
|
||||||
def api_request(params):
|
def raw_request(params):
|
||||||
app = current_app
|
app = current_app
|
||||||
url = 'https://www.wikidata.org/w/api.php?' + urlencode(params)
|
url = 'https://www.wikidata.org/w/api.php?' + urlencode(params)
|
||||||
client_key = app.config['CLIENT_KEY']
|
client_key = app.config['CLIENT_KEY']
|
||||||
|
@ -22,10 +22,10 @@ def api_request(params):
|
||||||
client_secret=client_secret,
|
client_secret=client_secret,
|
||||||
resource_owner_key=session['owner_key'],
|
resource_owner_key=session['owner_key'],
|
||||||
resource_owner_secret=session['owner_secret'])
|
resource_owner_secret=session['owner_secret'])
|
||||||
r = oauth.get(url, timeout=4)
|
return oauth.get(url, timeout=4)
|
||||||
reply = r.json()
|
|
||||||
|
|
||||||
return reply
|
def api_request(params):
|
||||||
|
return raw_request(params).json()
|
||||||
|
|
||||||
def get_token():
|
def get_token():
|
||||||
params = {
|
params = {
|
||||||
|
@ -39,6 +39,10 @@ def get_token():
|
||||||
|
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
def userinfo_call():
|
||||||
|
params = {'action': 'query', 'meta': 'userinfo', 'format': 'json'}
|
||||||
|
return api_request(params)
|
||||||
|
|
||||||
def get_username():
|
def get_username():
|
||||||
if 'owner_key' not in session:
|
if 'owner_key' not in session:
|
||||||
return # not authorized
|
return # not authorized
|
||||||
|
@ -46,8 +50,7 @@ def get_username():
|
||||||
if 'username' in session:
|
if 'username' in session:
|
||||||
return session['username']
|
return session['username']
|
||||||
|
|
||||||
params = {'action': 'query', 'meta': 'userinfo', 'format': 'json'}
|
reply = userinfo_call()
|
||||||
reply = api_request(params)
|
|
||||||
if 'query' not in reply:
|
if 'query' not in reply:
|
||||||
return
|
return
|
||||||
session['username'] = reply['query']['userinfo']['name']
|
session['username'] = reply['query']['userinfo']['name']
|
||||||
|
|
Loading…
Reference in a new issue