Oh well I do it manually and that's it

This commit is contained in:
Stefano Assenzo
2022-10-02 14:41:42 +02:00
parent 0506607c2b
commit 26aef80ebe

54
main.py
View File

@@ -21,7 +21,6 @@ from bson.objectid import ObjectId
import time import time
#Boh #Boh
import sys import sys
import threading
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.INFO,
@@ -48,7 +47,7 @@ logging.info("The bot started successfully.")
with open('/app/data/readme.txt', 'w') as f: with open('/app/data/readme.txt', 'w') as f:
f.close() f.close()
bot.send_message("771375637", "The bot was restarted") bot.send_message("771375637", "Please write /start")
#Command /start #Command /start
@bot.message_handler(commands=['start']) @bot.message_handler(commands=['start'])
@@ -57,12 +56,14 @@ def start_command(message):
logging.info("Triggered command START.") logging.info("Triggered command START.")
messageText = "✋ Welcome to <b>Epic Games Notifier</b>\n\n📱 You will be notified every week when there are new free games in the Epic Games Store. \n\n👨‍💻 Created and developed by @Stef58_Official" messageText = "✋ Welcome to <b>Epic Games Notifier</b>\n\n📱 You will be notified every week when there are new free games in the Epic Games Store. \n\n👨‍💻 Created and developed by @Stef58_Official"
bot.send_message(chat_id, messageText, parse_mode="HTML") bot.send_message(chat_id, messageText, parse_mode="HTML")
recheck_game()
#Command /comingsoon #Command /comingsoon
@bot.message_handler(commands=['comingsoon']) @bot.message_handler(commands=['comingsoon'])
def comingsoon(message): def comingsoon(message):
logging.info("Triggered command COMING SOON.") logging.info("Triggered command COMING SOON.")
chat_id = message.chat.id chat_id = message.chat.id
logging.info("Triggered command COMING SOON")
url = "https://api.plenusbot.xyz/epic_games?country=IT" url = "https://api.plenusbot.xyz/epic_games?country=IT"
response = requests.get(url).json() response = requests.get(url).json()
# Title of future games # Title of future games
@@ -140,7 +141,7 @@ def freenow(message):
img_3 = bot.send_photo(message.chat.id, image_currentgames3) # Send image second current games img_3 = bot.send_photo(message.chat.id, image_currentgames3) # Send image second current games
send_message = bot.send_message(chat_id, title_description_3, parse_mode="HTML") # Send all send_message = bot.send_message(chat_id, title_description_3, parse_mode="HTML") # Send all
except IndexError: except IndexError:
logging.info("No third game") print("No third game")
#Command /subscribe #Command /subscribe
@bot.message_handler(commands=['subscribe']) @bot.message_handler(commands=['subscribe'])
@@ -155,18 +156,28 @@ def subscribe(message):
with open('/app/data/readme.txt', 'w') as f: with open('/app/data/readme.txt', 'w') as f:
f.write(str(take_id)) f.write(str(take_id))
f.writelines('\n') f.writelines('\n')
a()
def recheck_game():
logging.info("Triggered RECHECK GAME.")
time.sleep(10)
a()
#Function for send every week the notification #Function for send every week the notification
def check_game(): def a():
logging.info("Triggered CHECK GAME.") logging.info("Triggered CHECK GAME.")
#Check for new games #Read all id on readme.txt
#schedule.every().thursday.do(freenow)
try: try:
#Check for new games
url = "https://api.plenusbot.xyz/epic_games?country=IT" url = "https://api.plenusbot.xyz/epic_games?country=IT"
global response
response = requests.get(url).json() response = requests.get(url).json()
# Title of current games
current_games_title1 = response['currentGames'][0]['title'] current_games_title1 = response['currentGames'][0]['title']
current_games_title2 = response['currentGames'][1]['title'] current_games_title2 = response['currentGames'][1]['title']
#Check first game
search_game1 = collection.find_one({"Game 1" : current_games_title1}) search_game1 = collection.find_one({"Game 1" : current_games_title1})
if search_game1 is None: if search_game1 is None:
#Send notification if title game is changed #Send notification if title game is changed
@@ -176,21 +187,22 @@ def check_game():
else: else:
#If new game is changed recheck every 10 second #If new game is changed recheck every 10 second
print("The game is not changed") print("The game is not changed")
print("Ok") recheck_game()
except: except:
logging.info("An error has occurred") print("An error occurred")
recheck_game()
else: else:
logging.info("An error has occurred") print("An error occurred")
recheck_game()
def send_automatically1(message): def send_automatically1():
logging.info("Triggered AUTOMATICALLY SEND MESSAGE.") logging.info("Triggered AUTOMATICALLY SEND MESSAGE.")
#Connect to the api
try: try:
#Connect to the api
url = "https://api.plenusbot.xyz/epic_games?country=IT" url = "https://api.plenusbot.xyz/epic_games?country=IT"
global response
response = requests.get(url).json() response = requests.get(url).json()
#All information for first game
current_games_title1 = response['currentGames'][0]['title'] # First title current games current_games_title1 = response['currentGames'][0]['title'] # First title current games
current_games_description1 = response['currentGames'][0]['description'] # First description current games current_games_description1 = response['currentGames'][0]['description'] # First description current games
current_games_startdate1 = response['currentGames'][0]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate'] # Public release first game current_games_startdate1 = response['currentGames'][0]['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate'] # Public release first game
@@ -226,18 +238,10 @@ def send_automatically1(message):
send_game2 = {"Game 2": current_games_title2} send_game2 = {"Game 2": current_games_title2}
senddata = collection.update_one({'_id':ObjectId("6319c0ac2ffd38ae32cd9ffa")}, {"$set": send_game2}, upsert=False) senddata = collection.update_one({'_id':ObjectId("6319c0ac2ffd38ae32cd9ffa")}, {"$set": send_game2}, upsert=False)
except: except:
logging.info("An error has occurred") print("An error occurred")
recheck_game()
else: else:
logging.info("An error has occurred") print("An error occurred")
recheck_game()
def check_game_threads():
t1 = threading.Thread(target=check_game)
t1.start()
t1.join()
print("Nice")
job = schedule.every(10).seconds.do(check_game_threads).tag("check_game")
schedule_check_game = schedule.get_jobs("check_game")
print(schedule_check_game)
bot.polling() bot.polling()