mirror of
https://github.com/assenzostefano/epic-games-notifier-telegram.git
synced 2025-06-27 09:02:57 +02:00
Add logging and fix little bug
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.env
|
.env
|
||||||
|
debug.log
|
22
main.py
22
main.py
@@ -19,7 +19,17 @@ import pymongo
|
|||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
#Libraries for research game on db
|
#Libraries for research game on db
|
||||||
import time
|
import time
|
||||||
|
#Boh
|
||||||
|
import sys
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(asctime)s [%(levelname)s] %(message)s",
|
||||||
|
handlers=[
|
||||||
|
logging.FileHandler("debug.log"),
|
||||||
|
logging.StreamHandler(sys.stdout)
|
||||||
|
]
|
||||||
|
)
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
API_TOKEN = os.getenv('BOT_TOKEN')
|
API_TOKEN = os.getenv('BOT_TOKEN')
|
||||||
bot = telebot.TeleBot(API_TOKEN)
|
bot = telebot.TeleBot(API_TOKEN)
|
||||||
@@ -42,6 +52,7 @@ def start_command(message):
|
|||||||
#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.")
|
||||||
chat_id = message.chat.id
|
chat_id = message.chat.id
|
||||||
logging.info("Triggered command COMING SOON")
|
logging.info("Triggered command COMING SOON")
|
||||||
url = "https://api.plenusbot.xyz/epic_games?country=IT"
|
url = "https://api.plenusbot.xyz/epic_games?country=IT"
|
||||||
@@ -83,6 +94,7 @@ def comingsoon(message):
|
|||||||
#Command /freenow
|
#Command /freenow
|
||||||
@bot.message_handler(commands=['freenow'])
|
@bot.message_handler(commands=['freenow'])
|
||||||
def freenow(message):
|
def freenow(message):
|
||||||
|
logging.info("Triggered command FREENOW.")
|
||||||
chat_id = message.chat.id
|
chat_id = message.chat.id
|
||||||
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()
|
||||||
@@ -125,23 +137,26 @@ def freenow(message):
|
|||||||
#Command /subscribe
|
#Command /subscribe
|
||||||
@bot.message_handler(commands=['subscribe'])
|
@bot.message_handler(commands=['subscribe'])
|
||||||
def subscribe(message):
|
def subscribe(message):
|
||||||
|
logging.info("Triggered command SUBSCRIBE.")
|
||||||
#Register the user
|
#Register the user
|
||||||
global chat_id
|
global chat_id
|
||||||
chat_id = message.chat.id
|
chat_id = message.chat.id
|
||||||
send_message = bot.send_message(chat_id, "✅ You have been successfully subscribed to Epic Games Store Free Games notifications!")
|
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
|
#Get the ids of all users who write /subscribe
|
||||||
take_id = message.from_user.id
|
take_id = message.from_user.id
|
||||||
with open('readme.txt', 'a+') as f:
|
with open('readme.txt', 'w') as f:
|
||||||
f.write(str(take_id))
|
f.write(str(take_id))
|
||||||
f.writelines('\n')
|
f.writelines('\n')
|
||||||
a()
|
a()
|
||||||
|
|
||||||
def recheck_game():
|
def recheck_game():
|
||||||
|
logging.info("Triggered RECHECK GAME.")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
a()
|
a()
|
||||||
|
|
||||||
#Function for send every week the notification
|
#Function for send every week the notification
|
||||||
def a():
|
def a():
|
||||||
|
logging.info("Triggered CHECK GAME.")
|
||||||
#Read all id on readme.txt
|
#Read all id on readme.txt
|
||||||
#schedule.every().thursday.do(freenow)
|
#schedule.every().thursday.do(freenow)
|
||||||
schedule.every(10).seconds.do(freenow)
|
schedule.every(10).seconds.do(freenow)
|
||||||
@@ -168,6 +183,7 @@ def a():
|
|||||||
|
|
||||||
|
|
||||||
def send_automatically1():
|
def send_automatically1():
|
||||||
|
logging.info("Triggered AUTOMATICALLY SEND MESSAGE.")
|
||||||
#Connect to the api
|
#Connect to the api
|
||||||
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()
|
||||||
@@ -197,6 +213,10 @@ def send_automatically1():
|
|||||||
img_1 = bot.send_photo(a, current_games_images1) # Send image first current games
|
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
|
send_message = bot.send_message(a, 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
|
#Update Collection with new game
|
||||||
send_game1 = {"Game 1": current_games_title1}
|
send_game1 = {"Game 1": current_games_title1}
|
||||||
senddata = collection.update_one({'_id':ObjectId("")}, {"$set": send_game1}, upsert=False)
|
senddata = collection.update_one({'_id':ObjectId("")}, {"$set": send_game1}, upsert=False)
|
||||||
|
0
requirements.txt
Normal file
0
requirements.txt
Normal file
Reference in New Issue
Block a user