1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/osu.py

24 lines
699 B
Python
Raw Normal View History

2017-02-07 21:24:49 +00:00
import asyncio
import requests
2017-02-20 10:16:04 +00:00
import functools
2017-02-07 21:24:49 +00:00
loop = asyncio.get_event_loop()
# Load Osu API key from the osutoken.txt file
file = open("osutoken.txt", "r")
token = file.read()
file.close()
async def get_user(user, mode=0):
print("[Osu!] Getting profile data for {} mode {}".format(user, mode))
params = {
"k": token,
"m": mode,
"u": user
}
# Get the data
2017-02-20 10:16:04 +00:00
r = await loop.run_in_executor(None, functools.partial(requests.get, timeout=6.1) 'https://osu.ppy.sh/api/get_user?k={k}&m={m}&u={u}'.format(**params))
2017-02-07 21:24:49 +00:00
if r.status_code == 200:
return r.json()[0]
else:
raise Exception("[Osu!] Unhandled exception during the API request")