Last active
January 6, 2017 19:05
-
-
Save apiarian/3bf841bb3681351dcb5198bc40249ba8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# licence: ¯\_(ツ)_/¯ | |
import requests | |
s = requests.Session() | |
d = { | |
'client_id': 'client_id', | |
'client_secret': 'client_secret', | |
'grant_type': 'password', | |
'username': 'username', | |
'password': 'password', | |
} | |
r = s.post('https://online-go.com/oauth2/access_token', | |
headers = { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
}, | |
data = d, | |
allow_redirects = False, | |
); | |
# print(r.request.method, r.request.url, r.request.body); | |
oauth2_json = r.json() | |
access_token = oauth2_json['access_token'] | |
refresh_token = oauth2_json['refresh_token'] | |
# print(oauth2_json) | |
# print() | |
r = s.get('https://online-go.com/api/v1/me/', | |
headers = { | |
'Authorization': 'Bearer {}'.format(access_token), | |
}, | |
) | |
def rank_to_display(rank_value): | |
if rank_value < 30: | |
return '%dk' % (30-rank_value,) | |
else: | |
return '%dd' % ((rank_value-30)+1) | |
my_info_json = r.json() | |
# print(my_info_json) | |
# print() | |
print('overall: {}, blitz: {}, live: {}, corr: {}'.format( | |
rank_to_display(my_info_json['ranking']), | |
rank_to_display(my_info_json['ranking_blitz']), | |
rank_to_display(my_info_json['ranking_live']), | |
rank_to_display(my_info_json['ranking_correspondence']), | |
)) | |
print() | |
r = s.post('https://online-go.com/api/v1/challenges', | |
headers = { | |
'Authorization': 'Bearer {}'.format(access_token), | |
}, | |
json = { | |
'game': { | |
'name': 'Lunch-hour Go', | |
'rules': 'japanese', | |
'ranked': True, | |
'handicap': -1, | |
'time_control': 'absolute', | |
'time_control_parameters': { | |
'time_control': 'absolute', | |
'total_time': 20*60, | |
}, | |
'pause_on_weekends': False, | |
'width': 19, | |
'height': 19, | |
'disable_analysis': False, | |
}, | |
'challenger_color': 'automatic', | |
'min_ranking': my_info_json['ranking']-2, | |
'max_ranking': my_info_json['ranking']+2, | |
}, | |
allow_redirects = False, | |
); | |
# print(r.request.method, r.request.url, r.request.headers, r.request.body) | |
# print() | |
# | |
# print(r.headers) | |
print(r.content) | |
# vim: ft=python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment