コード例 #1
0
ファイル: main.py プロジェクト: samx81/ramenbot-tw
def search_by_name(update, context):
    userinput = update.message.text
    s = dbHelper.query_like('name',userinput)
    message = ""
    if s:
        for a in s:
            message += "{id}, {name} - {location}\n".format(id = a['id'],name =a['name'],location=a['loc'][a['loc'].find('.')+1:])
        message += "\n使用 /id (店家編號) 取得更多資訊"
        update.message.reply_text(message)
コード例 #2
0
ファイル: main.py プロジェクト: samx81/ramenbot-tw
def by_type(update, context):
    cur_condition = "type"
    if update.callback_query is not None:
        query = update.callback_query.data
        s = dbHelper.query_like(cur_condition, query)
        if s:
            reply_markup = make_info_inline_kb(s[0]['gmapid'], cur_condition, query,QUERY_METHOD.LIKE)
            update.callback_query.edit_message_text(update.callback_query.message.text)
            update.callback_query.message.reply_markdown(make_info_str(s[0], True), reply_markup=reply_markup,
                                                         parse_mode=ParseMode.MARKDOWN)
            return ConversationHandler.END
        else:
            update.callback_query.message.reply_text("查無店家,試著輸入其他條件")
            return cur_condition
    else:
        update.callback_query.message.reply_text("格式有誤,請再試一次")
        return cur_condition
コード例 #3
0
ファイル: main.py プロジェクト: samx81/ramenbot-tw
def find_another(update,context):
    # get callback from query
    query = update.callback_query
    querylist = query.data.split(',')
    # column, condition,gmapid, method
    repeat = True
    while repeat:
        logger.info("looking for another")
        if querylist[2] == 'taipei':
            s = dbHelper.query_begin_with()[0]
        elif QUERY_METHOD(int(querylist[4])) == QUERY_METHOD.LIKE:
            s = dbHelper.query_like(querylist[1], querylist[2])[0]
        elif QUERY_METHOD(int(querylist[4])) == QUERY_METHOD.TIME:
            s = dbHelper.query_time(None,querylist[2])[0]
        else:
            s = dbHelper.query_specify([querylist[1]], [querylist[2]])[0]
        # TODO: specify correct condition
        if len(s)==1 or s['gmapid'] != querylist[3]:
            repeat = False

    reply_kb = make_info_inline_kb(s['gmapid'],querylist[1],querylist[2],QUERY_METHOD(int(querylist[4])))
    update.callback_query.edit_message_text(update.callback_query.message.text)
    update.callback_query.message.reply_markdown(make_info_str(s,True),reply_markup=reply_kb)
コード例 #4
0
ファイル: main.py プロジェクト: samx81/ramenbot-tw
def getinfo(update, context):
    if update.message:
        logger.info(update.message.text)
    else:
        logger.info(update.callback_query.data)
    logger.info(",".join(map(str, newshop)))
    try:
        if len(newshop) == 0:
            st = dbHelper.query_like('name',update.message.text)
            if st:
                update.message.reply_text('資料庫條目可能有重複,若為不同店家請繼續輸入')
                db_str = "重複列表:\n"
                for i in st:
                    db_str += i['name']+"\n"
                update.message.reply_markdown(db_str)

            newshop.append(update.message.text)
            update.message.reply_text(add_str_dict[0]+
                                      "\n長的像這樣 goo.gl/maps/[key]\n"
                                      "請輸入 [key] 部分或是整個網址")
            return "gathering"
        if len(newshop) == 1:
            # if find a '/' do
            gid = ""
            if update.message.text.find('/') == -1:
                gid = update.message.text
            # else if find googl do
            elif update.message.text.find('goo.gl/maps/') != -1:
                gid = update.message.text[
                      (update.message.text.find('goo.gl/maps/')+len('goo.gl/maps/'))
                      :]
            else:
                update.message.reply_text('請檢查你輸入的是否有誤\n'
                                          '格式為https://goo.gl/maps/________')
                return "gathering"
            newshop.append(gid)
            update.message.reply_text(add_str_dict[1])

            return "gathering"
        if len(newshop) == 2:
            valid_loc = check_valid_location(update.message.text)
            if valid_loc is not None:
                newshop.append(valid_loc)
                update.message.reply_text(add_str_dict[2])
            else:
                update.message.reply_text("請檢查你輸入的位置,捷運站請加\"站\""
                                          ",城市請加縣市區")
            return "gathering"
        if len(newshop) == 3:
            input = update.message.text
            wd = ""
            try:
                # number
                if is_int(input) and int(input) != -1:
                    wd = int(input)-1
                # only one char
                elif len(update.message.text) == 1:
                    if update.message.text == "無":
                        wd = -1
                    else:
                        wd = "星期"+input if input != "天" else "星期日"
                        wd = (list(week_day_dict.keys())[list(week_day_dict.values()).index(wd)])
                else:
                    wd = (list(week_day_dict.keys())[list(week_day_dict.values()).index(input)])
                if wd != "":
                    newshop.append(wd)
                    print(wd)
                    update.message.reply_text(add_str_dict[3])
                    return "gathering"
            except ValueError:
                update.message.reply_text("check input")
        if len(newshop) == 4:
            # deal with time
            tmp = str(update.message.text)
            timelist = list()
            if tmp.find(",") is not -1:
                tmp = tmp.split(",")
                timelist= tmp[0].split('-')+tmp[1].split('-')
            newshop.append(",".join(timelist))
            update.message.reply_text(add_str_dict[4])
            return "gathering"

        if len(newshop) == 5:
            newshop.append(update.message.text)
            update.message.reply_text(add_str_dict[5])
            return "gathering"
        if len(newshop) == 6:
            newshop.append(update.message.text)
            update.message.reply_text(add_str_dict[6])
            return "gathering"
        if len(newshop) == 7:
            newshop.append(update.message.text)
            update.message.reply_text(add_str_dict[7])
            return "preview"
    except AttributeError as e:
        logger.info(e)
        context.bot.send_message(chat_id=update.effective_chat.id, text="不正當的操作,請遵照對話互動或是輸入 /cancel 離開")