import csv from datetime import datetime from CsvGame import CsvGame def convertDateForPostgres(date): # Conversion de la chaîne de caractères en objet datetime date_obj = datetime.strptime(date, "%d/%m/%Y") # Conversion de l'objet datetime au format YYYY-MM-DD new_date_str = date_obj.strftime("%Y-%m-%d") return new_date_str def loadCsv(): gamesSettings = [] with open('config\gamesSettings.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 for row in csv_reader: if line_count > 0: game_nsuid = row[0] game_title = row[1] game_price_discount_alert = row[2] game_percentage_discount_alert = row[3] csvGame = CsvGame(game_nsuid, game_title, game_price_discount_alert, game_percentage_discount_alert) gamesSettings.append(csvGame) line_count += 1 return gamesSettings def isTheNsuidPresentInGameSettings(gamesSettings, nsuid): nsuid_found = False for currentGameSettings in gamesSettings: if(currentGameSettings.nsuid == nsuid ): nsuid_found = True return nsuid_found def arePriceConditionsMetForNotification(gamesSettings, current_nsuid, current_price, current_percentage): for currentGameSettings in gamesSettings: if(currentGameSettings.nsuid == current_nsuid ): setPrice = currentGameSettings.discount_price_alert setPercentage = currentGameSettings.discount_percentage_alert strMessage = "[Price Conditions] Current Game : " + str(current_price) + " / " + str(current_percentage) + " | Settled : " + str(setPrice) + " / " + str(setPercentage) print(strMessage) if((current_price <= float(setPrice)) or (current_percentage <= int(setPercentage))): return True return False