diff --git a/apps/fortnitewins/fortnite_wins.gif b/apps/fortnitewins/fortnite_wins.gif index 3de0ef3033..846503950f 100644 Binary files a/apps/fortnitewins/fortnite_wins.gif and b/apps/fortnitewins/fortnite_wins.gif differ diff --git a/apps/fortnitewins/fortnite_wins.star b/apps/fortnitewins/fortnite_wins.star index a9ba0d5c7f..29895f6ed1 100644 --- a/apps/fortnitewins/fortnite_wins.star +++ b/apps/fortnitewins/fortnite_wins.star @@ -24,7 +24,6 @@ yellow = "#ffcc66" blue = "#3399ff" icon_left = base64.decode("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAABiZJREFUWEft1nlsFNcdB/Dv3LP3YXuXxSfYRjgYY5yjgbhAgCpOUiIKLSZHKUmaPxICUo6qLVXSIFTSNocSzgolCkrSBIoBtRBM7kBMBJZ8EAwp2ARsLz7Wuzu7szs7O8fOVOuIKNQULQ2IfzLS/DVvfu/zvu/Ne0PgOl/Ede4fVwRo2/1Yw42LNh+4muicAEtuZM0Cn+tQMinNaphVufTePx3bcbUQOQGWzeSk7mHd6rAyqK9xY+78uXfXP/jO/quByAmwfAbX4Ml3Np/uE1FRaEXd1PE9BYUl1Xetala+LyInwFvP1AuhmOLmWQOhYBAutwelAf7o4uc6b73mgPbtSzr6gvFakjKRGDiH9q4oFjVW4ey/Y6npvOGZ8twJ9fsgLpvAqb2LFw4OpPfoGRmKMIx0IomwkEH72TgYisK9P5+/6raHmzZcM4ARWbkrY2YWUQSF5lf3Q9NNJNIGPm5PYlp1PmqryuTbVxywXjOA0v/AHsaStxAkhb0v7oFmAopmIp1hIRosKvwuLFh9OKd19L+Ql325o2ne/ra2/jtb2hI49lUE8252Y6LPApOlkdBYBDw8frWu46Ia3e8vebnyjn88mWsqlwXsWzdt16GOoUWTyj3oPC7Aa6cgiEnoJlBSFEB1sQ0L/th+UY31y/OV073xlRs/1bbmghgD2LnCkZxawgUm/zacaN042aQJBaWT7NB0Bi9t6QEyKnS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UWlBgaiYMVYWcTF10YKgvhVAoDUVWIVAGFMuFmoeervGW/eqzUe+BJXOEVQSh/oGmSZqmSUp00RA9NIrzeBRP9CJQmgeH2w2KZUASwLAH5nAEShaZhIR0LIVoTxqRSAaaqoMyNWgmbz3wpw7yv3vCd96Ev/4xN67AZ/cyHD+NZ+S3p98kEv6gB2JxDhwuEZTdBoIADBiAqv3nCKYgRST096YRH8rC1DU4aRI6xW+Zu651xf8EMFIHW3+vo6C0zDW3dt7NpM0nEKEeebIUCdUwJApISwuYOtoUzXZMleRmTdVlj9sBKWrtvHXNqdhIelfdC0Z72/2/338A+MGB6+7AvwEdoIw/I1JlXwAAAABJRU5ErkJggg==") default_username = None @@ -36,10 +35,18 @@ def float_to_string_without_trailing_decimal(f): else: return str(f) +def round_to_two_decimals(num): + shifted_value = num * 100 + if shifted_value >= 0: + rounded_shifted = int(shifted_value + 0.5) + else: + rounded_shifted = int(shifted_value - 0.5) + return rounded_shifted / 100.0 + ######################################################################################### Main Function ######################################################################################### def main(config): - decrypted_key = secret.decrypt("AV6+xWcEV7GacJDEp2zeLrBSz3B9Zs7vJXr0DjyUa2llQTDRSYQEZjfunRXRXG7cWxeIEda9H1nskXpFtFw1KmcYAf09+wjpCZe+T1p9vFdbYO72NYHc5s0vpjj+MXuqsQDhgkMPOlLpYdkH/Md0/aBnAdmU4lq4qWLx+kTMbnJAmfqido+6g1c=") + decrypted_key = secret.decrypt("AV6+xWcEtjzCMWUa+at2mAmFdMvwL4NMNReBrfTUKm4xnoqy2dbFJgOd9DW6NPcXn9YFo8zg6aVpoMgihOjr7E+jGhZ+zA4pFJ6yXff5IcNn/HlyAA22izWW4wCBY8s4rgdHsQEcZmpwuJTI9orRNwRQonai5Gc6Q1ixW75LuRXKJV3DUEkqJfcc") headers = { "Authorization": decrypted_key, } @@ -51,44 +58,38 @@ def main(config): if username == None: # Eror message prompting user to input a username into the app. message = "No username found... Input a username in the app to check your wins here!" else: - primary_url = "https://fortniteapi.io/v1/lookup?username=" + username - accountID_request = http.get(primary_url, headers = headers, ttl_seconds = 86400) - - if accountID_request.status_code != 200: # Can't find the passed in username. - message = "Couldn't find your Epic account information... Make sure to use your Epic account username and not your display name!" - print("Fortnite player lookup request failed because the username can't be found..") - else: # Username can be found, proceed. - accountID = accountID_request.json()["account_id"] - secondary_url = "https://fortniteapi.io/v1/stats?account=" + accountID - playerStats_request = http.get(secondary_url, headers = headers, ttl_seconds = 1200) - - if playerStats_request.status_code != 200: #Something went wrong and we can't get the account associated with the ID. - message = "We couldn't find a Fortnite account associated with the given Epic username." - print("Fortnite player stats request failed because something went wrong...") - - if playerStats_request.json().get("code", None) == "PRIVATE_ACCOUNT": - message = "Sorry, your account is private, so we can't view your stats! Make your account public to see stats." - print("Fortnite player stats request failed because the user's account is private.") - - else: - playerStats_request = playerStats_request.json() - squad_wins = "Squads: " + float_to_string_without_trailing_decimal(playerStats_request["global_stats"]["squad"]["placetop1"]) - trio_wins = "Trios: " + float_to_string_without_trailing_decimal(playerStats_request["global_stats"]["trio"]["placetop1"]) - duo_wins = "Duos: " + float_to_string_without_trailing_decimal(playerStats_request["global_stats"]["duo"]["placetop1"]) - solo_wins = "Solos: " + float_to_string_without_trailing_decimal(playerStats_request["global_stats"]["solo"]["placetop1"]) - - if show_kd: - squad_wins = squad_wins + " (K/D: " + str(playerStats_request["global_stats"]["squad"]["kd"]) + ")" - trio_wins = trio_wins + " (K/D: " + str(playerStats_request["global_stats"]["trio"]["kd"]) + ")" - duo_wins = duo_wins + " (K/D: " + str(playerStats_request["global_stats"]["duo"]["kd"]) + ")" - solo_wins = solo_wins + " (K/D: " + str(playerStats_request["global_stats"]["solo"]["kd"]) + ")" - if win_rate: - squad_wins = squad_wins + " (W/L: " + str(playerStats_request["global_stats"]["squad"]["winrate"]) + ")" - trio_wins = trio_wins + " (W/L: " + str(playerStats_request["global_stats"]["trio"]["winrate"]) + ")" - duo_wins = duo_wins + " (W/L: " + str(playerStats_request["global_stats"]["duo"]["winrate"]) + ")" - solo_wins = solo_wins + " (W/L: " + str(playerStats_request["global_stats"]["solo"]["winrate"]) + ")" - - message = solo_wins + " " + duo_wins + " " + trio_wins + " " + squad_wins + api_url = "https://fortnite-api.com/v2/stats/br/v2?name=" + username + playerStats_request = http.get(api_url, headers = headers, ttl_seconds = 900) + playerStats_request = playerStats_request.json() + + if playerStats_request["status"] == 403: #Something went wrong and we can't get the account associated with the ID. + message = "Sorry, your account is private, so we can't view your stats! Make your account public to see stats." + print("Fortnite player stats request failed because the user's account is private.") + + elif playerStats_request["status"] == 404: + message = "We couldn't find a Fortnite account associated with the given Epic username. Make sure to use your Epic account username and not your display name!" + print("Fortnite player stats request failed because something went wrong...") + + elif playerStats_request["status"] == 200: + solo_wins = "Solos: " + float_to_string_without_trailing_decimal(playerStats_request["data"]["stats"]["all"]["solo"]["wins"]) + duo_wins = "Duos: " + float_to_string_without_trailing_decimal(playerStats_request["data"]["stats"]["all"]["duo"]["wins"]) + squad_wins = "Squads: " + float_to_string_without_trailing_decimal(playerStats_request["data"]["stats"]["all"]["squad"]["wins"]) + + if show_kd: + solo_wins = solo_wins + " (K/D: " + str(round_to_two_decimals(playerStats_request["data"]["stats"]["all"]["solo"]["kd"])) + ")" + duo_wins = duo_wins + " (K/D: " + str(round_to_two_decimals(playerStats_request["data"]["stats"]["all"]["duo"]["kd"])) + ")" + squad_wins = squad_wins + " (K/D: " + str(round_to_two_decimals(playerStats_request["data"]["stats"]["all"]["squad"]["kd"])) + ")" + + if win_rate: + solo_wins = solo_wins + " (W/L: " + str(round_to_two_decimals(playerStats_request["data"]["stats"]["all"]["solo"]["winRate"])) + "%)" + duo_wins = duo_wins + " (W/L: " + str(round_to_two_decimals(playerStats_request["data"]["stats"]["all"]["duo"]["winRate"])) + "%)" + squad_wins = squad_wins + " (W/L: " + str(round_to_two_decimals(playerStats_request["data"]["stats"]["all"]["squad"]["winRate"])) + "%)" + + message = solo_wins + " " + duo_wins + " " + squad_wins + + else: + message = "Sorry, something went wrong." + print("Unkown error.") return render.Root( show_full_animation = True, diff --git a/apps/fortnitewins/manifest.yaml b/apps/fortnitewins/manifest.yaml index 56575be4f1..c8596bf141 100644 --- a/apps/fortnitewins/manifest.yaml +++ b/apps/fortnitewins/manifest.yaml @@ -1,8 +1,8 @@ --- id: fortnite-wins name: Fortnite Wins -summary: Tracks Fortnite wins -desc: Shows how many wins the user has in each main game mode (i.e., Solos, Duos, Trios, and Squads). +summary: Track Fortnite Wins +desc: Shows how many wins the user has in each main game mode (i.e., Solos, Duos, and Squads)! author: Hunter Berry fileName: fortnite_wins.star packageName: fortnitewins