From 4e7f318d79492601e5c810cfb51cbc7ceda27b8f Mon Sep 17 00:00:00 2001 From: neyi <65132648+neyi780@users.noreply.github.com> Date: Wed, 28 Jul 2021 19:28:54 +0200 Subject: [PATCH 1/2] a lot of stuff --- bazaar_prices.py | 93 +++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/bazaar_prices.py b/bazaar_prices.py index 4497899..a7c8ff5 100644 --- a/bazaar_prices.py +++ b/bazaar_prices.py @@ -3,6 +3,9 @@ import difflib from time import sleep +#Colored output +from colorama import Fore, Back, Style + response = requests.get("https://api.hypixel.net/skyblock/bazaar") names = [] @@ -20,70 +23,78 @@ def connection_info(response): sleep(1) print("Getting data...") sleep(1) - print("Data successfully received!") + print("Data successfully recived!") sleep(1) - # Get a list of all items' names def get_names(data): data = data.json() for i in data["products"]: names.append(i) - # define showing the output def print_price(response, requestedProduct): data = response.json() - trueRequestedProduct = requestedProduct.upper().replace("_", " ") - + trueRequestedProduct = requestedProduct.upper() try: trueRequestedProduct = difflib.get_close_matches(trueRequestedProduct, names)[0] - displayRequestedProduct = trueRequestedProduct.replace("_", " ").lower().title() - print("\n" + displayRequestedProduct) + requestedProduct = trueRequestedProduct.replace("_", " ").lower().title() + print("\n" + requestedProduct) except IndexError: - # no close matches pass - try: - product_sellPrice = data["products"][trueRequestedProduct]["sell_summary"][0]["pricePerUnit"] - product_buyPrice = data["products"][trueRequestedProduct]["buy_summary"][0]["pricePerUnit"] - - # difference between sell and buy - diff = product_buyPrice - product_sellPrice - - # amount of items insta sold/bought this week - salesweek = data['products'][trueRequestedProduct]['quick_status']['sellMovingWeek'] - buysweek = data['products'][trueRequestedProduct]['quick_status']['buyMovingWeek'] - - print("-----------------------------------------------------------------------------") - print(f"One {displayRequestedProduct} sells for {str('{:,}'.format(product_sellPrice))} coins ") - print(f"One {displayRequestedProduct} costs {str('{:,}'.format(product_buyPrice))} coins ") - print("") - print(f"The difference between buy and sell price is {str('{:,}'.format(round(diff)))} coins") - print(f"") - print("Amount of items insta-bought this week: " + str("{:,}".format(buysweek))) - print("Amount of items insta-sold this week: " + str("{:,}".format(salesweek))) - print("-----------------------------------------------------------------------------") + product_sellPrice = data["products"][trueRequestedProduct]["sell_summary"][0]["pricePerUnit"] + product_buyPrice = data["products"][trueRequestedProduct]["buy_summary"][0]["pricePerUnit"] + # difference between sell and buy - except KeyError: - pass - print(f"Hey! '{requestedProduct}' is not tradable on the bazaar.") + differenceBuySell = product_buyPrice - product_sellPrice + # amount of items insta sold/bought this week -# Code calling functions + salesWeek = data['products'][trueRequestedProduct]['quick_status']['sellMovingWeek'] + buysWeek = data['products'][trueRequestedProduct]['quick_status']['buyMovingWeek'] + print( + Fore.YELLOW + Style.BRIGHT + "-----------------------------------------------------------------------------" + Style.RESET_ALL) + print( + f"One {Style.BRIGHT + Fore.YELLOW}{requestedProduct}{Style.RESET_ALL} sells for {Back.BLACK + Fore.YELLOW + Style.BRIGHT}{str('{:,}'.format(product_sellPrice))}{Style.RESET_ALL} coins ") + print( + f"One {Style.BRIGHT + Fore.YELLOW}{requestedProduct}{Style.RESET_ALL} costs {Back.BLACK + Fore.YELLOW + Style.BRIGHT}{str('{:,}'.format(product_buyPrice))}{Style.RESET_ALL} coins ") + print( + f"64x {Style.BRIGHT + Fore.YELLOW}{requestedProduct}{Style.RESET_ALL} costs {Back.BLACK + Fore.YELLOW + Style.BRIGHT}{str('{:,}'.format(product_buyPrice * 64))}{Style.RESET_ALL} coins ") + print("") + print( + f"The difference between buy and sell price is {Back.BLACK + Fore.YELLOW + Style.BRIGHT}{str('{:,}'.format(round(differenceBuySell, 2)))}{Style.RESET_ALL} coins") + print("") + print("Amount of items insta-bought this week: " + Back.BLACK + Fore.YELLOW + Style.BRIGHT + str( + "{:,}".format(buysWeek)) + Style.RESET_ALL + " items") + print("Amount of items insta-sold this week: " + Back.BLACK + Fore.YELLOW + Style.BRIGHT + str( + "{:,}".format(salesWeek)) + Style.RESET_ALL + " items") + print( + Fore.YELLOW + Style.BRIGHT + "-----------------------------------------------------------------------------" + Style.RESET_ALL) + +# COde calling functions connection_info(response) get_names(response) -keepGoing = "y" -# Forever if keepGoing is y, do this stuff. If not, thank and stop -while keepGoing == "y": - requestedProduct = input("\nWhat product would you like to search for? | e.g; enchanted lava bucket: ") - - print_price(response, requestedProduct) +#Instead of asking if you want to search an other product, it asks until it gives a valid product +while True: + while True: + requestedProduct = input("\nWhat product would you like to search for? | e.g; enchanted lava bucket: ") + requestedProduct = requestedProduct.replace("_", " ") + try: + print_price(response, requestedProduct.lower()) + break + except KeyError: + pass + print(f"Hey! '{Fore.YELLOW + Style.BRIGHT}{requestedProduct}{Style.RESET_ALL}' is not tradable on the bazaar.") - keepGoing = input("Would you like to search for another product? (y/n) ") - if keepGoing == "n": + keepGoing = input("Would you like to search for another product? (y/n): ") + if keepGoing == "y": + continue + else: break + +print("") print("Thank you for using Hypixel-Skyblock-Utilities by Lennster1") -# :) +# :) \ No newline at end of file From 10a1971860544e5c3335991f021cac9f2ae43546 Mon Sep 17 00:00:00 2001 From: lennster1 Date: Wed, 28 Jul 2021 16:32:23 -0400 Subject: [PATCH 2/2] changed to received --- bazaar_prices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazaar_prices.py b/bazaar_prices.py index a7c8ff5..2eaa853 100644 --- a/bazaar_prices.py +++ b/bazaar_prices.py @@ -23,7 +23,7 @@ def connection_info(response): sleep(1) print("Getting data...") sleep(1) - print("Data successfully recived!") + print("Data successfully received!") sleep(1) # Get a list of all items' names