Removed module

This commit is contained in:
Administrator 2022-05-02 17:22:50 +02:00
parent fb65d7e13e
commit e3fdb19411
6 changed files with 85 additions and 17 deletions

View File

@ -1,2 +1,3 @@
# Bot API
BOT_API_KEY=
DATABASE_CONNECTION=mysql://scott:tiger@localhost/foo'

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# IntelliJ / PyCharm
.idea/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

View File

@ -1,3 +1,4 @@
pyTelegramBotAPI~=4.5.0
python-dotenv~=0.20.0
APScheduler~=3.9.1
SQLAlchemy~=1.4.36

View File

@ -9,23 +9,25 @@ __license__ = "None"
# main bot at http://t.me/guess_the_price_bot
# debug bot at http://t.me/amazondebug_bot
from dotenv import load_dotenv
import telebot
from telebot import types
from apscheduler.schedulers.background import BackgroundScheduler
import logging
import os
import sys
import telebot
from dotenv import load_dotenv
from telebot import types
from source.db import User, session
load_dotenv(dotenv_path='.env') # load environment variables
bot_version = "0.0.1" # version of bot
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
@bot.message_handler(commands=['start', 'Start'])
def send_start(message):
""" Sending welcome message to new user
:type message: message object bot
:param message: message that was reacted to, in this case always containing '/start'
@ -36,11 +38,12 @@ def send_start(message):
"""
bot.reply_to(message, "Welcome to this amazon prices guesser bot")
telebot.logger.setLevel(logging.DEBUG)
@bot.inline_handler(lambda query: query.query == 'text') # inline prints for debugging
def query_text(inline_query):
""" Output in the console about current user actions and status of bot
:type inline_query:
:param inline_query:
@ -56,8 +59,8 @@ def query_text(inline_query):
except Exception as e:
print(e)
def main_loop():
def main_loop():
""" Start bot
:raises: none
@ -65,6 +68,7 @@ def main_loop():
"""
bot.infinity_polling()
if __name__ == '__main__':
try:
main_loop()

59
source/db.py Normal file
View File

@ -0,0 +1,59 @@
__author__ = "Florian Kaiser"
__copyright__ = "Copyright 2022, GuessThePrice"
__credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof"]
__license__ = "GPL 3.0"
__version__ = "1.0.0"
import os
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine, Boolean, DateTime, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine(os.getenv("DATABASE_CONNECTION"), echo=True)
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
telegram_id = Column(Integer, primary_key=True)
username = Column(String)
admin = Column(Boolean)
def __repr__(self):
return "<User(telegram_id='%s', username='%s', admin='%s')>" % (self.telegram_id, self.username, self.admin)
class Score(Base):
__tablename__ = 'score'
telegram_id = Column(Integer, ForeignKey('user.telegram_id'), primary_key=True)
date = Column(DateTime, primary_key=True)
product_id = Column(String, ForeignKey('product.product_id'))
guess = Column(Float)
score = Column(Integer)
def __repr__(self):
return "<Score(telegram_id='%s', date='%s', product_id='%s', guess='%s', score='%s')>" % (self.telegram_id, self.date, self.product_id, self.guess, self.score)
class Product(Base):
__tablename__ = 'product'
product_id = Column(String, primary_key=True)
price = Column(Float)
image_link = Column(String)
title = Column(String)
description = Column(String)
date = Column(DateTime)
def __repr__(self):
return "<Product(product_id='%s', price='%s', image_link='%s', title='%s', description='%s', date='%s')>" % (
self.product_id, self.price, self.image_link, self.title, self.description, self.date)
# Create all tables by issuing CREATE TABLE commands to the DB.
Base.metadata.create_all(engine)
# Creates a new session to the database by using the engine we described.
Session = sessionmaker(bind=engine)
session = Session()

View File