diff --git a/data/readme.txt b/app/data/readme.txt similarity index 100% rename from data/readme.txt rename to app/data/readme.txt diff --git a/main.py b/main.py index 1dff256..1e1cf19 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,7 @@ collection = database["epicgames-telegram"] logging.info("The bot started successfully.") #Create file for save id user -with open('/app/data/readme.txt', 'w') as f: +with open('app/data/readme.txt', 'w') as f: f.close() bot.send_message("771375637", "Please write /start") @@ -153,7 +153,7 @@ def subscribe(message): send_message = bot.send_message(chat_id, "✅ You have been successfully subscribed to Epic Games Store Free Games notifications!") #Get the ids of all users who write /subscribe take_id = message.from_user.id - with open('/app/data/readme.txt', 'w') as f: + with open('app/data/readme.txt', 'w') as f: f.write(str(take_id)) f.writelines('\n') a() @@ -198,6 +198,7 @@ def a(): def send_automatically1(): logging.info("Triggered AUTOMATICALLY SEND MESSAGE.") try: + print("Try to send first game") #Connect to the api url = "https://api.plenusbot.xyz/epic_games?country=IT" response = requests.get(url).json() @@ -210,38 +211,46 @@ def send_automatically1(): current_games_price1 = response['currentGames'][0]['price']['totalPrice']['fmtPrice']['originalPrice'] current_games_images1 = response['currentGames'][0]['keyImages'][0]['url'] # First image current games - #All information for second game - current_games_title2 = response['currentGames'][1]['title'] # Second title current game - current_games_images2 = response['currentGames'][1]['keyImages'][0]['url'] # Second image current game - current_games_description2 = response['currentGames'][1]['description'] # Second description current game - current_games_startdate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate'] #Public release second game - current_games_endate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate'] # End public release second game - current_games_price2 = response['currentGames'][1]['price']['totalPrice']['fmtPrice']['originalPrice'] # Original price second game - - with open('/app/data/readme.txt', 'r') as f: + with open('app/data/readme.txt', 'r') as f: for line in f: y = line.split() - a = (', '.join(y)) + b = (', '.join(y)) #Send first and second message when the free game title change title_description_1 = current_games_title1 + "\n\nAbout:\n" + current_games_description1 + "\n" + "\nStart Date:\n" + current_games_startdate1 + "\n" + "\nEnd Date:\n" + current_games_endate1 + "\n" + "\nPrice:\n" + current_games_price1 + " → " + "Free" # Send title, description, start date and price first current game - img_1 = bot.send_photo(a, current_games_images1) # Send image first current games - send_message = bot.send_message(a, title_description_1, parse_mode="HTML") # Send all + img_1 = bot.send_photo(b, current_games_images1) # Send image first current games + send_message = bot.send_message(b, title_description_1, parse_mode="HTML") # Send all - title_description_2 = current_games_title2 + "\n\nAbout:\n" + current_games_description2 + "\n" + "\nStart Date:\n" + current_games_startdate2 + "\n" + "\nEnd Date:\n" + current_games_endate2 + "\n" + "\nPrice:\n" + current_games_price2 + " → " + "Free" # Send title, description, start date and price second current game - img_2 = bot.send_photo(a, current_games_images2) # Send image second current games - send_message = bot.send_message(a, title_description_2, parse_mode="HTML") # Send all - #Update Collection with new game send_game1 = {"Game 1": current_games_title1} senddata = collection.update_one({'_id':ObjectId("6319beba54b4d66a40e2d3eb")}, {"$set": send_game1}, upsert=False) - - send_game2 = {"Game 2": current_games_title2} - senddata = collection.update_one({'_id':ObjectId("6319c0ac2ffd38ae32cd9ffa")}, {"$set": send_game2}, upsert=False) except: print("An error occurred") recheck_game() else: - print("An error occurred") - recheck_game() + print("no ok") + try: + print("Try to send second game") + #All information for second game + current_games_title2 = response['currentGames'][1]['title'] # Second title current game + current_games_images2 = response['currentGames'][1]['keyImages'][0]['url'] # Second image current game + current_games_description2 = response['currentGames'][1]['description'] # Second description current game + current_games_startdate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate'] #Public release second game + current_games_endate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate'] # End public release second game + current_games_price2 = response['currentGames'][1]['price']['totalPrice']['fmtPrice']['originalPrice'] # Original price second game + + send_game2 = {"Game 2": current_games_title2} + senddata = collection.update_one({'_id':ObjectId("6319c0ac2ffd38ae32cd9ffa")}, {"$set": send_game2}, upsert=False) + + with open('app/data/readme.txt', 'r') as f: + for line in f: + y = line.split() + c = (', '.join(y)) + title_description_2 = current_games_title2 + "\n\nAbout:\n" + current_games_description2 + "\n" + "\nStart Date:\n" + current_games_startdate2 + "\n" + "\nEnd Date:\n" + current_games_endate2 + "\n" + "\nPrice:\n" + current_games_price2 + " → " + "Free" # Send title, description, start date and price second current game + img_2 = bot.send_photo(c, current_games_images2) # Send image second current games + send_message = bot.send_message(c, title_description_2, parse_mode="HTML") # Send all + + except: + print("An error occurred") + recheck_game() bot.polling() \ No newline at end of file