mirror of
https://github.com/assenzostefano/epic-games-notifier-telegram.git
synced 2025-02-16 19:30:41 +01:00
So now the bot don't crash for second game, thanks epic games
This commit is contained in:
parent
7bb4f499da
commit
b1540a2370
@ -13,24 +13,25 @@ def freegame_command(message, bot):
|
||||
current_games_startdate1 = response['currentGames'][0]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate']
|
||||
current_games_endate1 = response['currentGames'][0]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate']
|
||||
current_games_price1 = response['currentGames'][0]['price']['totalPrice']['fmtPrice']['originalPrice']
|
||||
|
||||
#Take data from API (Current Game 2)
|
||||
image_currentgames2 = response['currentGames'][1]['keyImages'][0]['url'] # First image current games
|
||||
current_games2 = response['currentGames'][1]['title'] # First title current games
|
||||
current_games_description2 = response['currentGames'][1]['description'] # First description current games
|
||||
current_games_startdate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate']
|
||||
current_games_endate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate']
|
||||
current_games_price2 = response['currentGames'][1]['price']['totalPrice']['fmtPrice']['originalPrice']
|
||||
|
||||
#Send notification to user (Current Game 1)
|
||||
title_description_1 = current_games1 + "\n\n<b>About:</b>\n" + current_games_description1 + "\n" + "\n<b>Start Date:</b>\n" + current_games_startdate1 + "\n" + "\n<b>End Date:</b>\n" + current_games_endate1 + "\n" + "\n<b>Price:</b>\n" + current_games_price1 + " → " + "Free" # Send title, description, start date and price first current game
|
||||
img_1 = bot.send_photo(message.chat.id, image_currentgames1) # Send image first current games
|
||||
send_message = bot.send_message(chat_id, title_description_1, parse_mode="HTML") # Send all
|
||||
|
||||
try:
|
||||
#Take data from API (Current Game 2)
|
||||
image_currentgames2 = response['currentGames'][1]['keyImages'][0]['url'] # First image current games
|
||||
current_games2 = response['currentGames'][1]['title'] # First title current games
|
||||
current_games_description2 = response['currentGames'][1]['description'] # First description current games
|
||||
current_games_startdate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate']
|
||||
current_games_endate2 = response['currentGames'][1]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate']
|
||||
current_games_price2 = response['currentGames'][1]['price']['totalPrice']['fmtPrice']['originalPrice']
|
||||
|
||||
#Send notification to user (Current Game 2)
|
||||
title_description_2 = current_games2 + "\n\n<b>About:</b>\n" + current_games_description2 + "\n" + "\n<b>Start Date:</b>\n" + current_games_startdate2 + "\n" + "\n<b>End Date:</b>\n" + current_games_endate2 + "\n" + "\n<b>Price:</b>\n" + current_games_price2 + " → " + "Free" # Send title, description, start date and price second current game
|
||||
img_2 = bot.send_photo(message.chat.id, image_currentgames2) # Send image second current games
|
||||
send_message = bot.send_message(chat_id, title_description_2, parse_mode="HTML") # Send all
|
||||
title_description_2 = current_games2 + "\n\n<b>About:</b>\n" + current_games_description2 + "\n" + "\n<b>Start Date:</b>\n" + current_games_startdate2 + "\n" + "\n<b>End Date:</b>\n" + current_games_endate2 + "\n" + "\n<b>Price:</b>\n" + current_games_price2 + " → " + "Free" # Send title, description, start date and price second current game
|
||||
img_2 = bot.send_photo(message.chat.id, image_currentgames2) # Send image second current games
|
||||
send_message = bot.send_message(chat_id, title_description_2, parse_mode="HTML") # Send all
|
||||
except:
|
||||
print("Second current game not found")
|
||||
|
||||
#Try search third game
|
||||
try:
|
||||
|
@ -15,28 +15,30 @@ def a(collection_game, collection_id, bot):
|
||||
response = requests.get(url).json() #API in JSON
|
||||
|
||||
# Title of current games
|
||||
current_games_title1 = response['currentGames'][0]['title'] #Title of first game
|
||||
current_games_title2 = response['currentGames'][1]['title'] #Title of second game
|
||||
try:
|
||||
current_games_title1 = response['currentGames'][0]['title'] #Title of first game
|
||||
search_game1 = collection_game.find_one({"Game 1" : current_games_title1}) #Search game1 in MongoDB
|
||||
|
||||
#Check first game
|
||||
search_game1 = collection_game.find_one({"Game 1" : current_games_title1}) #Search game1 in MongoDB
|
||||
search_game2 = collection_game.find_one({"Game 2" : current_games_title2}) #Search game2 in MongoDB
|
||||
if search_game1 is None: #If game1 is not in MongoDB send notification
|
||||
if search_game1 is None: #If game1 is not in MongoDB send notification
|
||||
#Send notification if title game is changed
|
||||
print("Found a new 1 game!")
|
||||
print("Now I'm sending the notification to everyone.")
|
||||
notification_game.notification_game1(collection_game, collection_id, bot)
|
||||
if search_game2 is None: #If game2 is not in MongoDB send notification
|
||||
#Send notification if title game is changed
|
||||
print("Found a new 2 game!")
|
||||
print("Now I'm sending the notification to everyone.")
|
||||
notification_game.notification_game2(collection_game, collection_id, bot)
|
||||
else:
|
||||
#If new game is not changed recheck every 10 second
|
||||
print("The game is not changed")
|
||||
print("Found a new 1 game!")
|
||||
print("Now I'm sending the notification to everyone.")
|
||||
notification_game.notification_game1(collection_game, collection_id, bot)
|
||||
except:
|
||||
print("Current Game 1 not found")
|
||||
recheck_game(collection_game, collection_id, bot)
|
||||
|
||||
try:
|
||||
current_games_title2 = response['currentGames'][1]['title'] #Title of second game
|
||||
search_game2 = collection_game.find_one({"Game 2" : current_games_title2}) #Search game2 in MongoDB
|
||||
if search_game2 is None: #If game2 is not in MongoDB send notification
|
||||
#Send notification if title game is changed
|
||||
print("Found a new 2 game!")
|
||||
print("Now I'm sending the notification to everyone.")
|
||||
notification_game.notification_game2(collection_game, collection_id, bot)
|
||||
except:
|
||||
print("Current Game 2 not found")
|
||||
recheck_game(collection_game, collection_id, bot)
|
||||
except:
|
||||
print("An error occurred")
|
||||
recheck_game(collection_game, collection_id, bot)
|
||||
else:
|
||||
recheck_game(collection_game, collection_id, bot)
|
Loading…
x
Reference in New Issue
Block a user