Exemplo n.º 1
0
def read_article_feed(feed):
    """Парсим и пробуем отправить ссылки в канал slack"""
    feeds = feedparser.parse(feed)
    for article in feeds['entries']:
        title, link = [article['title'], article['link']]
        if db.article_not_exist(article['title']):
            try:
                db.insert(title, link)
                bot.send_message(config.CHAT_ID, f"{title}\n{link}")
            except Exception as ex:
                print(ex)
Exemplo n.º 2
0
def show_categories_menu(chat_id, message_id=None):
    user = User.query.filter_by(id=chat_id).first()
    responce_data = {
        'chat_id': chat_id,
        'text':
        f'{interface.CURRENT_BALANCE} {user.balance} {interface.RUBLE}',
        'reply_markup': interface.CATEGORIES_MENU
    }

    if not message_id:
        bot.send_message(responce_data)
    else:
        responce_data['message_id'] = message_id
        bot.edit_message_text(responce_data)
Exemplo n.º 3
0
def show_main_menu(chat_id, responce_text='', message_id=None):
    user = User.query.filter_by(id=chat_id).first()
    responce_text += f'\n\n{interface.CURRENT_BALANCE} {user.balance} {interface.RUBLE}'

    responce_data = {
        'chat_id': chat_id,
        'text': responce_text,
        'reply_markup': interface.MENU
    }

    if not message_id:
        bot.send_message(responce_data)
    else:
        responce_data['message_id'] = message_id
        bot.edit_message_text(responce_data)
Exemplo n.º 4
0
def delete_category(chat_id):
    user_categories = json.dumps({
        'keyboard': [[{
            'text': category.name
        }] for category in Category.query.filter_by(user_id=chat_id).all()],
        'resize_keyboard':
        True,
        'one_time_keyboard':
        True
    })

    bot.send_message({
        'chat_id': chat_id,
        'text': interface.SELECT_DELETE_CATEGORY,
        'reply_markup': user_categories
    })
Exemplo n.º 5
0
def start(chat_id, user_fname):
    if not User.query.filter_by(id=chat_id).all():
        new_user = User(id=chat_id)
        default_categories = [
            Category(name=category_name, user=new_user)
            for category_name in interface.DEFAULT_CATEGORIES
        ]

        db.session.add(new_user)
        db.session.add_all(default_categories)
        db.session.commit()

    bot.send_message({
        'chat_id':
        chat_id,
        'text':
        f'\U0001F305 Добрый день, {user_fname}! {interface.START}'
    })
    show_main_menu(chat_id)
Exemplo n.º 6
0
def index():
    ids = csvhandler.read()
    data = ""
    [bot.send_message(int(chat_id), "File was comitted") for chat_id in ids]
    try:
        payload = loads(request.data)
        for commit_num, data_dict in enumerate(payload['commits']):
            data += f"Commit{commit_num + 1}\n"
            data += "Login: "******"Message: " + data_dict['message'] + "\n"
            data += "Timestamp: " + data_dict['timestamp'] + '\n'
            data += "Modified files: " + str(data_dict['modified']) + '\n'
            data += "Added files: " + str(data_dict['added']) + '\n'
            data += "Removed files: " + str(data_dict['removed']) + '\n'
            data += "-" * 25 + '\n'
            [bot.send_message(int(chat_id), data) for chat_id in ids]
    except Exception as e:
        [bot.send_message(int(chat_id), "Can't get data.") for chat_id in ids]
        print(e)
    return "Ok!"
Exemplo n.º 7
0
def select_date(chat_id):
    total_dates = []
    for cost in Cost.query.filter_by(user_id=chat_id).all():
        date = f'{cost.debit_date.month}/{cost.debit_date.year}'
        if date not in total_dates:
            total_dates.append(date)

    bot.send_message({
        'chat_id':
        chat_id,
        'text':
        interface.SELECT_DATE,
        'reply_markup':
        json.dumps({
            'keyboard': [[{
                'text': date
            }] for date in total_dates],
            'resize_keyboard': True,
            'one_time_keyboard': True
        })
    })
Exemplo n.º 8
0
def show_statistics(chat_id, date=None):
    user = User.query.filter_by(id=chat_id).first()

    if not date:
        responce_text = '📈 Статистика за текущий месяц:\n\n'
        responce_text += f'{interface.CURRENT_BALANCE} {user.balance} {interface.RUBLE}\n'
        date = datetime.now(tz=pytz.timezone('Asia/Yekaterinburg')).date()
    else:
        error_responce_data = {
            'chat_id': chat_id,
            'text': interface.ERROR_STATISTICS_DATE
        }

        # date = '12/2019'.split()
        date = date.split('/')
        if len(date) != 2:
            bot.send_message(error_responce_data)
            return

        try:
            date = datetime(day=1, month=int(date[0]), year=int(date[1]))
        except (ValueError, TypeError):
            bot.send_message(error_responce_data)
            return

        responce_text = f'📈 Статистика за {date.month} месяц {date.year} года:\n\n'

    user_categories = Category.query.filter_by(user=user).all()

    categories_costs_price = {
        category.name: decimal.Decimal('0.00')
        for category in user_categories
    }
    total_costs_price = 0

    for cost in Cost.query.filter_by(user=user).all():
        is_same_month = cost.debit_date.year == date.year
        is_same_month *= cost.debit_date.month == date.month
        if is_same_month:
            price = cost.price
            categories_costs_price[cost.category.name] += price
            total_costs_price += price

    responce_text += f'💸 Сумма расходов: {total_costs_price} {interface.RUBLE}\n\n'
    for category, price in categories_costs_price.items():
        responce_text += f'{category} - {price} {interface.RUBLE}\n'

    bot.send_message({'chat_id': chat_id, 'text': responce_text})
Exemplo n.º 9
0
def add_category(chat_id):
    bot.send_message({'chat_id': chat_id, 'text': interface.ADD_CATEGORY})
Exemplo n.º 10
0
def help(chat_id):
    bot.send_message({'chat_id': chat_id, 'text': interface.HELP})
Exemplo n.º 11
0
def top_up_balance(chat_id):
    bot.send_message({'chat_id': chat_id, 'text': interface.TOP_UP_BALANCE})
Exemplo n.º 12
0
def add_cost(chat_id):
    bot.send_message({'chat_id': chat_id, 'text': interface.INPUT_PRICE_COST})
Exemplo n.º 13
0
from packtpub_scraper import crawler
from bs4 import BeautifulSoup
from telegram_bot import bot

response_data = crawler.get_response()
response_soup = BeautifulSoup(response_data, 'html.parser')
formatted_book_title = crawler.get_book_title(response_soup)
formatted_book_description = crawler.get_book_description(response_soup)
formatted_book_image_url = crawler.get_book_image(response_soup)

text_to_send = "<strong>" + formatted_book_title + " </strong>" \
               "<i>" + formatted_book_description + "</i>" \
               "<a href='" + formatted_book_image_url + "'>Image Url</a>"

user_list = bot.check_updates()
for user in user_list:
    bot.send_message(user['id'], text_to_send)