def getStats(api_key, username, gametype, stats_refresh):
    ## Request player stats from the osu!api.
    try:
        stats_json = json.loads(
            osu_apy.get_user(api_key, username, str(gametype), "string", ""))

        ## Exit if the player request does not exist.
        if (str(stats_json) == "[]"):
            print "\n    Invalid configuration. The user \"" + username + "\" does not exist."
            sys.exit()

        return int(stats_json[0]["pp_rank"]), float(
            stats_json[0]["pp_raw"]), float(stats_json[0]["accuracy"])

    ## Unable to connect to osu!api
    except IOError:
        print "\n    Unable to connect to osu!api. Will retry again in " + str(
            stats_refresh) + " seconds."

        return 0, 0.0, 0.0

    ## Invalid JSON returned from osu!api
    except ValueError:
        ## Exit if the API key is invalid.
        print "\n    Invalid JSON returned from osu!api. Will retry again in " + str(
            stats_refresh) + " seconds."

        return 0, 0.0, 0.0

    except KeyboardInterrupt:
        return 0, 0.0, 0.0
def getStats(api_key, username, gametype, stats_refresh):
	## Request player stats from the osu!api.
	try:
		stats_json = json.loads(osu_apy.get_user(api_key, username, str(gametype), "string", ""))
		
		## Exit if the player request does not exist.
		if (str(stats_json) == "[]"):
			print "\n    Invalid configuration. The user \"" + username + "\" does not exist."
			sys.exit()

		return int(stats_json[0]["pp_rank"]), float(stats_json[0]["pp_raw"]), float(stats_json[0]["accuracy"])

	## Unable to connect to osu!api
	except IOError:
		print "\n    Unable to connect to osu!api. Will retry again in " + str(stats_refresh) + " seconds."

		return 0, 0.0, 0.0

	## Invalid JSON returned from osu!api
	except ValueError:
		## Exit if the API key is invalid.
		print "\n    Invalid JSON returned from osu!api. Will retry again in " + str(stats_refresh) + " seconds."
		
		return 0, 0.0, 0.0

	except KeyboardInterrupt:		
		return 0, 0.0, 0.0
Esempio n. 3
0
def osu():
    username = "******" + request.args['user_name']
    channel = "#" + request.args['channel_name']
    userid = request.args['text']
    osu = json.loads(
        osu_apy.get_user(config.osukey, userid, 0, "", 1).decode('utf8'))
    if osu != []:
        osu = osu[0]
        osu['accuracy'] = '{:.2f}%'.format(float(osu['accuracy']))
        payload = {
            "channel":
            channel,
            "username":
            "******",
            "icon_url":
            "http://a.pomf.hummingbird.moe/bnzlnp.png",
            "attachments": [{
                "thumb_url":
                "http://a.ppy.sh/" + osu['user_id'] + "_1.png",
                "fallback":
                username + " Osu! stats for:" + osu['username'] +
                "\n Accuracy:" + osu['accuracy'] + " Rank: " + osu['pp_rank'] +
                " PP:" + osu['pp_raw'] + " Plays:" + osu['playcount'],
                "text":
                username + " Osu! stats for: <https://osu.ppy.sh/u/" +
                osu['username'] + "|" + osu['username'] + "> :" +
                osu['country'] + ":",
                "title":
                osu['username'],
                "fields": [{
                    "title": "Rank",
                    "value": osu['pp_rank'],
                    "short": True
                }, {
                    "title": "Accuracy",
                    "value": osu['accuracy'],
                    "short": True
                }, {
                    "title": "PP",
                    "value": osu['pp_raw'],
                    "short": True
                }, {
                    "title": "Play count",
                    "value": osu['playcount'],
                    "short": True
                }],
                "color":
                "#FF66A9"
            }]
        }
        r = requests.post(config.webhook_url, data=json.dumps(payload))
        return "", 200
    return "User not found you, " + random.choice(insults), 200
Esempio n. 4
0
def osu():
    username = "******" + request.args['user_name']
    channel = "#" + request.args['channel_name']
    userid = request.args['text']
    osu = json.loads(osu_apy.get_user(config.osukey, userid, 0, "", 1).decode('utf8'))
    if osu != []:
        osu = osu[0]
        osu['accuracy'] = '{:.2f}%'.format(float(osu['accuracy']))
        payload = {
        "channel": channel,
        "username": "******",
        "icon_url": "http://a.pomf.hummingbird.moe/bnzlnp.png",
        "attachments": [{
                "thumb_url": "http://a.ppy.sh/" + osu['user_id'] + "_1.png",
                "fallback": username + " Osu! stats for:" + osu['username'] + "\n Accuracy:" + osu['accuracy'] + " Rank: " + osu['pp_rank'] + " PP:" + osu['pp_raw'] + " Plays:" +osu['playcount'],
                "text": username + " Osu! stats for: <https://osu.ppy.sh/u/" + osu['username'] + "|" + osu['username'] + "> :" + osu['country'] + ":",
                "title" : osu['username'],
                "fields": [{
                    "title": "Rank",
                    "value": osu['pp_rank'],
                    "short": True
                }, {
                    "title": "Accuracy",
                    "value": osu['accuracy'],
                    "short": True
                }, {
                    "title": "PP",
                    "value": osu['pp_raw'],
                    "short": True
                }, {
                    "title": "Play count",
                    "value": osu['playcount'],
                    "short": True
                }],
            "color": "#FF66A9"
        }]
        }
        r = requests.post(config.webhook_url, data=json.dumps(payload))
        return "", 200
    return "User not found you, " + random.choice(insults), 200
Esempio n. 5
0
print("Retrieving Beatmap info by beatmap ID.\n")

print(osu_apy.get_beatmaps(dev_key, "", "", "256754", ""))

print("\n==TEST 4==")
print("Retrieving Beatmap info by user ID. (Used a song I played to get back relevant info.)\n")

print(osu_apy.get_beatmaps(dev_key, "", "", "256754", "2770894"))

print("\n=SET 2===================================================================")
print("osu_apy.get_user Method.")

print("\n==TEST 1==")
print("Retrieving user using defaults.\n")

print(osu_apy.get_user(dev_key, "2770894", "", "", ""))

print("\n==TEST 2==")
print("Retrieving user by mode.\n")

print(osu_apy.get_user(dev_key, "2770894", "0", "", ""))

print("\n==TEST 3==")
print("Retrieving user by user type (id).\n")

print(osu_apy.get_user(dev_key, "2770894", "", "id", ""))

print("\n==TEST 4==")
print("Retrieving user by user type (string).\n")

print(osu_apy.get_user(dev_key, "albinohat", "", "string", ""))
Esempio n. 6
0
print "Retrieving Beatmap info by beatmap ID.\n"

print osu_apy.get_beatmaps(dev_key, "", "", "256754", "")

print "\n==TEST 4=="
print "Retrieving Beatmap info by user ID. (Used a song I played to get back relevant info.)\n"

print osu_apy.get_beatmaps(dev_key, "", "", "256754", "2770894")

print "\n=SET 2==================================================================="
print "osu_apy.get_user Method."

print "\n==TEST 1=="
print "Retrieving user using defaults.\n"

print osu_apy.get_user(dev_key, "2770894", "", "", "")

print "\n==TEST 2=="
print "Retrieving user by mode.\n"

print osu_apy.get_user(dev_key, "2770894", "0", "", "")

print "\n==TEST 3=="
print "Retrieving user by user type (id).\n"

print osu_apy.get_user(dev_key, "2770894", "", "id", "")

print "\n==TEST 4=="
print "Retrieving user by user type (string).\n"

print osu_apy.get_user(dev_key, "albinohat", "", "string", "")