#imports import urllib.request import json #defines variables used in functions pp = ["0"] totalpp = 0 index = 0 #gets JSON from a url def getJSON(url): global data response = urllib.request.urlopen(url).read() json_obj = str(response, 'utf-8') data = json.loads(json_obj) return #calculates total pp based on pp[] def calcPP(): global index global totalpp for value in pp: totalpp += float(value) * 0.95**index index+= 1 return key = input('What is your osu! API key?\n') user = input('What is your osu! username?\n') getJSON("https://osu.ppy.sh/api/get_user_best?k=" + key + "&type=string&u=" + user + "&limit=100") #appends the pp amounts from data to pp[] for object in data: pp.append(object['pp']) #gets user pp getJSON("https://osu.ppy.sh/api/get_user?k=" + key + "&type=string&u=" + user) #puts user pp into a variable called userpp for object in data: userpp = object['pp_raw'] userrank = object['pp_rank'] #arranges pp from greatest to lowest pp.sort() pp.reverse() #without extra value calcPP() #calculates bonus pp bonuspp = float(userpp) - totalpp #asks the user for their expected pp expectedPP = input('What is the amount of pp you expect to gain from this play?\n') pp.append(expectedPP) #arranges pp from greatest to lowest (again) pp.sort() pp.reverse() totalpp = 0; index = 0; #with extra value calcPP() output = totalpp + bonuspp url = "https://osudaily.net/data/getPPRank.php?t=pp&v=" + str(output) + "&m=0" response = urllib.request.urlopen(url).read() rankGain = str(response, 'utf-8') print("You are expected to gain +" + str(float(output) - float(userpp)) + " pp and move up +" + str(int(userrank) - int(rankGain)) + " ranks from this play!")