Beispiel #1
0
def send_typings():
    """Send chat status to users."""
    try:
        queue = db_tools.get_users_for_typing()
    except:
        return
    for queue_item in queue:
        try:
            bot.send_chat_action(queue_item.user.telegram_id,
                                 queue_item.pre_message)
        except Exception:
            db_tools.session.delete(queue_item)
            db_tools.session.commit()
def sendAction(chat_id, action):
    return {
        "action": action,
        "chat_id": chat_id
    } if bot.send_chat_action(chat_id, action) else {
        "action": False,
        "chat_id": chat_id
    }
Beispiel #3
0
def analyze_coin(cid, mid, coin_name):
    lang = db.get_lang(cid)
    curr = db.get_currency(cid)
    with get_coin_name(cid, coin_name) as coin:
        if coin is None:
            raise UnknownCoinError(coin_name)
        coin = coins[coin]
        xdate = [(date.today() - timedelta(days=x)).strftime('%d-%m-%Y')
                 for x in range(10, 0, -1)]
        yprice = [
            cg.get_coin_history_by_id(
                id=coin, date=d,
                string='false')['market_data']['current_price'][curr]
            for d in xdate
        ]
        bot.send_chat_action(cid, 'upload_photo')
        Path('./temp/image/').mkdir(parents=True, exist_ok=True)
        path = str(Path('./temp/image/' + str(cid) + str(mid) + '.png'))
        create_graph(xdate, yprice, path, coin, lang, curr)
        with open(path, 'rb') as plot:
            bot.send_photo(cid, plot)
        os.remove(path)