diff --git a/bot.py b/bot.py index 98dcdb3..2e7cd98 100644 --- a/bot.py +++ b/bot.py @@ -12,17 +12,10 @@ This bot logs all messages sent in a Telegram Group to a database. from __future__ import print_function import sys from telegram.ext import Updater, CommandHandler, MessageHandler, Filters -import logging import os from model import User, Message, session from time import strftime -# Enable logging -logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.INFO) - -logger = logging.getLogger(__name__) - # Define a few command handlers. These usually take the two arguments bot and # update. Error handlers also receive the raised TelegramError object in error. @@ -95,7 +88,8 @@ def add_user(user_id, first_name, last_name, username): def error(bot, update, error): """Log Errors caused by Updates.""" - logger.warning('Update "%s" caused error "%s"', update, error) + print("Update '{}' caused error '{}'".format(update, error), file=sys.stderr) + def main(): diff --git a/model.py b/model.py index e819443..6436c81 100644 --- a/model.py +++ b/model.py @@ -1,10 +1,10 @@ from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, func from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declarative_base -import ConfigParser -config = ConfigParser.ConfigParser() -config.read("config.cnf") -postgres_url = config.get('postgres', 'postgres_url') +import os + +postgres_url = os.environ["TELEGRAM_BOT_POSTGRES_URL"] + ''' This model has been referenced from: https://www.pythoncentral.io/sqlalchemy-orm-examples/ @@ -14,7 +14,7 @@ Base = declarative_base() class User(Base): - __tablename__ = 'users' + __tablename__ = 'telegram_users' id = Column(Integer, primary_key=True) first_name = Column(String) last_name = Column(String) @@ -22,9 +22,9 @@ class User(Base): class Message(Base): - __tablename__ = 'messages' + __tablename__ = 'telegram_messages' id = Column(Integer, primary_key=True) - user_id = Column(Integer, ForeignKey('users.id'), nullable=False) + user_id = Column(Integer, ForeignKey('telegram_users.id'), nullable=False) message = Column(String) # Use default=func.now() to set the default hiring time # of an Employee to be the current time when an