Now it shouldn't crash anymore.
TO-DO: Add User IDs to MongoDB Multi-threading for game re-search
This commit is contained in:
parent
26aef80ebe
commit
2d5c70673d
55
main.py
55
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\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(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\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(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\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(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()
|
Loading…
Reference in New Issue