Beispiel #1
0
def receiver(track_id, *args):
    """
    check if this track is done
    No result in database would return none, so do a query and insert
    :param track_id: express id
    :param args: usually Telegram message_id and chat_id(user_id)
    :return: message to be sent to the client
    """
    # 1. query from database
    # 2. older or none, query kuaidi100, update database
    # 3. return status result

    db = Database()
    data = db.retrieve({'track_id': track_id})
    try:
        db_time = float(data[0][6])
    except IndexError:
        db_time = 0

    r = utils.reply_refuse()
    try:
        r = __doing_query(db_time, track_id, args, data)
    except Exception as e:
        print(e)
    finally:

        return r
Beispiel #2
0
def track_express(message):
    """
    get_season_count text/voice message, all digits means express id. Otherwise sends Turing or refuse message
    :param message: Telegram message sent by user.
    :return: None
    """
    if os.name == 'nt':
        temp = os.environ.get('TMP')
    else:
        temp = '/tmp'

    if message.voice:
        bot.send_chat_action(message.chat.id, 'record_audio')
        # download the file
        file_info = bot.get_file(message.voice.file_id)
        voice_file = requests.get(
            'https://api.telegram.org/file/bot{0}/{1}'.format(
                TOKEN, file_info.file_path))
        file_path = os.path.join(temp, message.voice.file_id + '.ogg')
        with open(file_path, 'wb') as f:
            f.write(voice_file.content)
        message.text = utils.voice_to_text(file_path)

    if u'4C7' in message.text:
        bot.send_chat_action(message.chat.id, 'typing')
        r = utils.reply_refuse()
        bot.send_message(message.chat.id, r)
    elif message.text.isdigit():
        bot.send_chat_action(message.chat.id, 'typing')
        r = kuaidi100.receiver(message.text, message.message_id,
                               message.chat.id)
        if u'单号不存在或者已经过期' in r:
            bot.reply_to(message, '汝的单号可能刚刚生成,暂无信息,不如稍后试试?')
        else:
            bot.reply_to(message, r, parse_mode='Markdown')
    # use turing bot
    elif TURING_KEY == '':
        bot.send_chat_action(message.chat.id, 'typing')
        r = utils.reply_refuse()
        bot.send_message(message.chat.id, r)
    else:
        bot.send_chat_action(message.chat.id, 'typing')
        r = turing.send_turing(TURING_KEY, message.text, message.chat.id)
        bot.send_message(message.chat.id, r)

    return r
Beispiel #3
0
def bot_quick_delete(message):
    if message.reply_to_message is None:
        bot.send_chat_action(message.chat.id, 'typing')
        bot.send_message(message.chat.id, utils.reply_refuse())
    else:
        s = message.reply_to_message.text
        msg = kuaidi100.delete(s.split()[0])
        bot.send_chat_action(message.chat.id, 'typing')
        bot.send_message(message.chat.id, msg)
Beispiel #4
0
def track_express(message):
    """
    process ordinary message, all digits means express id. Otherwise active Turing or refuse message
    :param message: Telegram message sent by user.
    :return: None
    """
    if message.text.isdigit():
        bot.send_chat_action(message.chat.id, 'typing')
        r = kuaidi100.recv(message.text, message.message_id, message.chat.id)
        bot.send_message(message.chat.id, r)
    # use turing bot
    elif TURING_KEY == '':
        bot.send_chat_action(message.chat.id, 'typing')
        bot.send_message(message.chat.id, utils.reply_refuse())
    else:
        bot.send_chat_action(message.chat.id, 'typing')
        r = turing.send_turing(TURING_KEY, message.text, message.chat.id)
        bot.send_message(message.chat.id, r)