Add files

This commit is contained in:
olari
2019-05-15 17:44:39 +03:00
parent ad2727652d
commit 4ec0e2569d
3 changed files with 90 additions and 0 deletions

47
python/web/get_7k_pp.py Executable file
View File

@@ -0,0 +1,47 @@
import requests
import json
import sys
if len(sys.argv) < 3:
print("usage: python get_7k_pp.py [api key] [username]")
exit(0)
api_key = sys.argv[1]
usernames = sys.argv[2:]
def get_json(url):
page = requests.get(url)
try:
page.raise_for_status()
except:
print("Could not get '{}'".format(url))
return []
return json.loads(page.text)
def get_user_best(api_key, username):
return get_json("https://osu.ppy.sh/api/get_user_best?k={}&limit=100&m=3&u={}".format(api_key, username))
def get_beatmap(api_key, id):
return get_json("https://osu.ppy.sh/api/get_beatmaps?k={}&b={}".format(api_key, id))
for username in usernames:
scores_7k = []
pp_7k = 0.0
for score in get_user_best(api_key, username):
info = get_beatmap(api_key, score["beatmap_id"])[0]
if info["diff_size"] == '7':
# theres probably a prettier solution for this
percentage = 100.0
for num in range(len(scores_7k)):
percentage *= 0.95
pp_7k += float(score["pp"]) / 100.0 * percentage
scores_7k.append("[{:.2f}+ ({:.2f}%)] {:.2f} {} [{}] {}k".format(pp_7k, percentage, float(score["pp"]), info["title"], info["version"], score["score"][:3]))
print("7k pp for '{}'".format(username))
print("Total = {}".format(pp_7k))
for score_7k in scores_7k:
print(score_7k)