From 7c5b50359dc43e72eefc8eee942a7de34115cc88 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 26 Jan 2016 19:00:35 +0100 Subject: [PATCH] Aggiunto controllo degli errori --- osu.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/osu.py b/osu.py index d9525ee0..fcce3df7 100644 --- a/osu.py +++ b/osu.py @@ -14,7 +14,10 @@ def getbeatmap(num): 'b': num, } r = requests.get("https://osu.ppy.sh/api/get_beatmaps", params=parametri).json() - return r[0] + if len(r) >= 1: + return r[0] + else: + raise NameError def getuser(user, mode=0): @@ -28,7 +31,10 @@ def getuser(user, mode=0): 'm': mode } r = requests.get("https://osu.ppy.sh/api/get_user", params=parametri).json() - return r[0] + if len(r) >= 1: + return r[0] + else: + raise NameError def getscores(beatmap, mode=0, limit=100, user=None): @@ -75,4 +81,7 @@ def getuserrecent(user, mode=0): 'limit': 1, } r = requests.get("https://osu.ppy.sh/api/get_user_recent", params=parametri).json() - return r[0] + if len(r) >= 1: + return r[0] + else: + raise NameError