From 1ce737159fc083f3d4cce314d62fe78d2eaa0d94 Mon Sep 17 00:00:00 2001 From: Emily Lycett Date: Thu, 12 Nov 2020 16:58:50 +0000 Subject: [PATCH] achieve % working --- .vs/Chatbot/v16/.suo | Bin 36352 -> 36352 bytes .vs/slnx.sqlite | Bin 90112 -> 90112 bytes Chatbot.py | 30 ++++++++++++++++-------------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.vs/Chatbot/v16/.suo b/.vs/Chatbot/v16/.suo index 646c3605c89770aae5eab85520b75dcb5a3bb1e8..cfbd3bef7d70c6c4defaee77c8f6d42b68f3662d 100644 GIT binary patch delta 97 zcmZpe!_+W`X+sVZ>w^osZwYNKWctm_YEZix#AKVL$YSi~XttSOqfARslmP*ZfK0~C Y(}GG_SxgKJO*ivLl*wUJP?jYQ0C~I@3IG5A delta 97 zcmZpe!_+W`X+sVZtAJPhR=&-JOuv~~3uOI4Otx8yEQZF;Mw|IH%CrP|7!W`O$mHBS XEvS^0#n8mqa5H~InH)9+Wm)0?pp6t% diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 66b022c982401c30622edb4bfe77c5d8d4af27aa..4bcdaf256121d122163d8dd540d76742d503a24a 100644 GIT binary patch delta 123 zcmZoTz}j$tb%Hdb*+dyjQA-U diff --git a/Chatbot.py b/Chatbot.py index e7b64ec..15319a8 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -24,28 +24,30 @@ api = WebAPI(key=steamApiKey) steamID= "STEAM_0:0:73873614" #this is Emily's steamID which is useful to use as a stub when testing def steamAchievementPercentages(steamID, gameID): #Emily - as you can see it's going well achieveList= requests.get("http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=" +gameID+ "&key=" +steamApiKey+ "&steamid=" +steamID) - totalAchieves = 1 - achievesCompleted=0 - print (len(achieveList.text)) + totalAchieves = 0 + achievesCompleted = 0 achieveList = achieveList.text achieveList = achieveList.replace("\"", " ") - achieveList = achieveList.replace("{", "\"") - achieveList = achieveList.replace("}", "\"") - achieveList = achieveList.strip("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,:0123456789\" ") + achieveList = achieveList.replace("},{", "-") + achieveList = achieveList.strip("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,:0123456789\" {}") + achieveList = list(achieveList.split("-")) + print (achieveList) for achieve in achieveList: - print (achieve) - if "\"achieved\":0" in achieve: + if "achieved :0" in achieve: totalAchieves = totalAchieves + 1 - if "\"achieved\":1" in achieve: + if "achieved :1" in achieve: achievesCompleted = achievesCompleted + 1 totalAchieves = totalAchieves + 1 - percentage= round ((achievesCompleted/totalAchieves)*100, 2) - print(achievesCompleted) - print(totalAchieves) - return percentage - + if totalAchieves > 0: + percentage= round ((achievesCompleted/totalAchieves)*100, 2) + return percentage + else: + return 0 #print (steamAchievementPercentages("76561198108012956", "582010")) +#print (steamAchievementPercentages("76561198047733265", "582010")) + + #==================END OF DEFINITIONS===================