Ejemplo n.º 1
0
def show_my_stock(userID, user_name, msg):
    db = constructor_stock()
    collect = db[user_name]
    dataList = list(collect.find({"userID": userID}))
    if dataList == []: return "您的股票清單為空,請透過指令新增股票至清單中"
    content = ""
    for i in range(len(dataList)):
        content += stockprice.getprice(dataList[i]["favorite_stock"], msg)
    return content
Ejemplo n.º 2
0
def process_text_message(event):
    global producer  #
    global consumer  #
    global server  #
    global r  #

    nowtime = str(
        time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
    msg = str(event.message.text).upper().strip()
    # 取出消息內User的資料
    profile = line_bot_api.get_profile(event.source.user_id)
    #     print(profile)

    #取出userid, displayname 丟回全域變數
    profile_dict = vars(profile)
    print("使用者輸入內容 =", msg, " ,LINE名字 =", profile_dict.get("display_name"),
          " ,使用者 =", profile_dict.get("user_id"), " ,輸入內容時間 =", nowtime)

    ID = profile_dict.get("user_id")  #
    text = event.message.text  #
    query = str(text)  #
    groupid = str(ID)  #

    #使用者及使用者輸入內容匯入kafka
    kafkaproducer(server=server, topic='2_resquest', ID=ID, query=query)  #

    if msg == '股票推薦':
        line_bot_api.push_message(ID, TextSendMessage(text='請稍等,\n資料產生中!!'))

        user_type = str(r.hget('attribute', ID))
        user_type += '_'
        user_type += str(datetime.datetime.now().strftime('%Y%m%d'))
        res = pro_kafkaconsumer(server=server,
                                groupid='groupid_1',
                                topic='promote_stock',
                                ID=user_type)  #此ID為type1(kafka內的)
        Stock_list = [i for i in eval(res[user_type]).keys()]
        Str = "股票推薦清單" + emoji_upinfo
        Str += '\n'
        Str += "======================="
        Str += '\n'
        for stl in Stock_list:
            Str += stl
            Str += '\n'

        Str += '======================'
        line_bot_api.push_message(ID, TextSendMessage(text=Str))

    elif msg == '.2-1_10%內可接受範圍':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.2-3_50%內可接受範圍':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.2-4_100%以上':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.3-1_1個月內':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.3-4_1年以上':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.4-1_每天花費1~2小時':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.4-3_每月花費1~2小時':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.5-1_高風險高報酬':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.6-1_投資一定有風險':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.7-1_我很積極布局':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.7-2_我要觀察一陣子':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.7-4_認賠殺出':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.8-1_我喜愛賺價差':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    elif msg == '.8-2_我喜愛超高報酬':
        res = kafkaconsumer(server=server,
                            groupid=groupid,
                            topic='1_resquest',
                            ID=ID)  #
        res = res[ID]  #
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=str(res)))

    # 個股新聞
    elif re.match('N[0-9]{4}', msg):
        stockNumber = msg[1:5]
        content = app_1_news.single_stock(stockNumber)
        line_bot_api.push_message(
            ID, TextSendMessage('即將給您編號' + stockNumber + '\n個股新聞!'))
        line_bot_api.push_message(ID, content)
        btn_msg = Msg_Template.stock_reply_other_news(stockNumber)
        line_bot_api.push_message(ID, btn_msg)

    # 每週新聞回顧
    elif re.match("每週新聞回顧", msg):
        line_bot_api.push_message(ID,
                                  TextSendMessage("我們將給您最新的周回顧,\n請點選圖片連結!!"))
        line_bot_api.push_message(ID, app_1_news.weekly_finance_news())

    # 查詢某檔股票開高收低價格
    elif re.match('S[0-9]', msg):
        stockNumber = msg[1:]
        stockName = stockprice.get_stock_name(stockNumber)
        if stockName == "no":
            line_bot_api.push_message(ID, TextSendMessage("股票編號錯誤"))
        else:
            line_bot_api.push_message(
                ID, TextSendMessage('稍等一下,\n查詢編號' + stockNumber + '\n的資訊中...'))
            content_text = stockprice.getprice(stockNumber, msg)
            content = Msg_Template.stock_reply_other_price(
                stockNumber, content_text)
            line_bot_api.push_message(ID, content)

    #K線圖     #OK
    elif re.match("K[0-9]{4}", msg):
        stockNumber = msg[1:]
        content = Msg_Template.kchart_msg + "\n" + Msg_Template.kd_msg
        line_bot_api.push_message(ID, TextSendMessage(content))
        line_bot_api.push_message(ID, TextSendMessage('稍等一下,\nK線圖繪製中...'))
        k_imgurl = kchart.draw_kchart(stockNumber)
        line_bot_api.push_message(
            ID,
            ImageSendMessage(original_content_url=k_imgurl,
                             preview_image_url=k_imgurl))
        btn_msg = Msg_Template.stock_reply_other_K(stockNumber)
        line_bot_api.push_message(ID, btn_msg)

    #MACD指標     #OK
    elif re.match("MACD[0-9]", msg):
        stockNumber = msg[4:]
        content = Msg_Template.macd_msg
        line_bot_api.push_message(
            ID, TextSendMessage('稍等一下,\n將給您編號' + stockNumber + '\nMACD指標...'))
        line_bot_api.push_message(ID, TextSendMessage(content))
        MACD_imgurl = Technical_Analysis.MACD_pic(stockNumber, msg)
        line_bot_api.push_message(
            ID,
            ImageSendMessage(original_content_url=MACD_imgurl,
                             preview_image_url=MACD_imgurl))
        btn_msg = Msg_Template.stock_reply_other_MACD(stockNumber)
        line_bot_api.push_message(ID, btn_msg)

    #RSI指標  #OK
    elif re.match('RSI[0-9]', msg):
        stockNumber = msg[3:]
        line_bot_api.push_message(
            ID, TextSendMessage('稍等一下,\n將給您編號' + stockNumber + '\nRSI指標...'))
        RSI_imgurl = Technical_Analysis.stock_RSI(stockNumber)
        line_bot_api.push_message(
            ID,
            ImageSendMessage(original_content_url=RSI_imgurl,
                             preview_image_url=RSI_imgurl))
        btn_msg = Msg_Template.stock_reply_other_RSI(stockNumber)
        line_bot_api.push_message(ID, btn_msg)

    #BBAND指標      #OK
    elif re.match("BBAND[0-9]", msg):
        stockNumber = msg[5:]
        content = Msg_Template.bband_msg
        line_bot_api.push_message(ID, TextSendMessage(content))
        line_bot_api.push_message(
            ID, TextSendMessage('稍等一下,\n將給您編號' + stockNumber + '\nBBand指標...'))
        BBANDS_imgurl = Technical_Analysis.BBANDS_pic(stockNumber, msg)
        line_bot_api.push_message(
            ID,
            ImageSendMessage(original_content_url=BBANDS_imgurl,
                             preview_image_url=BBANDS_imgurl))
        btn_msg = Msg_Template.stock_reply_other_BBAND(stockNumber)
        line_bot_api.push_message(ID, btn_msg)

    #畫近一年股價走勢圖      #OK
    elif re.match("P[0-9]{4}", msg):
        stockNumber = msg[1:]
        line_bot_api.push_message(
            ID, TextSendMessage('稍等一下,\n將給您編號' + stockNumber + '\n股價走勢圖!'))
        trend_imgurl = stockprice.stock_trend(stockNumber, msg)
        line_bot_api.push_message(
            ID,
            ImageSendMessage(original_content_url=trend_imgurl,
                             preview_image_url=trend_imgurl))
        btn_msg = Msg_Template.stock_reply_other_P(stockNumber)
        line_bot_api.push_message(ID, btn_msg)

    # 個股年收益率分析圖 #OK
    elif re.match('E[0-9]{4}', msg):
        targetStock = msg[1:]
        line_bot_api.push_message(
            ID, TextSendMessage('分析' + targetStock + '中,\n年收益率圖產生中,\n稍等一下。'))
        imgurl2 = stockprice.show_return(targetStock, msg)
        line_bot_api.push_message(
            ID,
            ImageSendMessage(original_content_url=imgurl2,
                             preview_image_url=imgurl2))
        btn_msg = Msg_Template.stock_reply_other_E(targetStock)
        line_bot_api.push_message(ID, btn_msg)

    #三大法人買賣資訊  #OK
    elif re.match('F[0-9]', msg):
        stockNumber = msg[1:]
        line_bot_api.push_message(
            ID,
            TextSendMessage('稍等一下,\n將給您編號' + stockNumber + '\n三大法人買賣資訊...'))
        content = Institutional_Investors.institutional_investors(stockNumber)
        line_bot_api.push_message(ID, TextSendMessage(content))
        btn_msg = Msg_Template.stock_reply_other_F(stockNumber)
        line_bot_api.push_message(ID, btn_msg)

    # 籌碼面分析圖    #失敗_有空從做此步
#     elif re.match('C[0-9]', msg):
#         targetStock = msg[1:]
#         line_bot_api.push_message(ID, TextSendMessage('分析' + targetStock + '中,\n籌碼面分析圖產生中,\n稍等一下。'))
#         imgurl2 = Institutional_Investors.institutional_investors_pic(targetStock)
#         if imgurl2 == "股票代碼錯誤!":
#             line_bot_api.push_message(ID, TextSendMessage("股票代碼錯誤!"))

#         line_bot_api.push_message(ID, ImageSendMessage(original_content_url=imgurl2, preview_image_url=imgurl2))
#         btn_msg = Msg_Template.stock_reply_other(targetStock)
#         line_bot_api.push_message(ID, btn_msg)

#功能說明
    elif msg == '功能說明':
        line_bot_api.reply_message(event.reply_token, \
            TextSendMessage(text='您好~\n在此說明我的功能!\n\nK+個股代號(舉例:K2330),\n=>會產生出2330的K線圖。\n\nN+個股代號(舉例:N2330),\n=>會顯示近期2330的新聞連結。\n\nS+個股代號(舉例:S2330),\n=>會顯示最近2330的\n開、高、收、低價格。\n\nMACD+個股代號(舉例:MACD2330),\n=>會產生出2330的MACD指標圖。\n\nRSI+個股代號(舉例:RSI2330),\n=>會產生出2330的RSI指標圖。\n\nBBAND+個股代號(舉例:BBAND2330),\n=>會產生出2330的BBAND指標圖。\n\nP+個股代號(舉例:P2330),\n=>會產生出2330的一年股價走勢圖。\n\nE+個股代號(舉例:E2330),\n=>會產生出2330的年收益率分析圖。\n\nF+個股代號(舉例:F2330),\n=>會產生出2330三大法人買賣資訊。\n\n或者點選"股票推薦",\n推薦適合您的股票名單。\n\n功能說明完畢,\n謝謝觀看!!'))

    #問候語回應
    elif msg in ("你好", "哈嘍", 'HI', 'hi', '嗨', "妳好", "您好", "Hi", "hI"):
        line_bot_api.reply_message(event.reply_token, \
            TextSendMessage(text='您好~歡迎加入股市小子!\n下方圖文選單可以點選!\n或請點選下方"功能說明",\n會詳列出我的功能說明!'))

    else:
        pass

    # 讀取本地檔案,並轉譯成消息
    result_message_array = []
    replyJsonPath = "素材/" + event.message.text + "/reply.json"
    result_message_array = detect_json_array_to_new_message_array(
        replyJsonPath)

    # 發送
    line_bot_api.reply_message(event.reply_token, result_message_array)
Ejemplo n.º 3
0
def handle_message(event):
    msg = str(event.message.text).upper().strip()  # 使用者輸入的內容
    profile = line_bot_api.get_profile(event.source.user_id)
    user_name = profile.display_name  #使用者名稱
    uid = profile.user_id  # 發訊者ID
    #================================
    # 問卷
    #   if re.match("問卷分析", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.greeting_msg))
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q1))
    #       content = questionnaire.Q1_menu()
    #       line_bot_api.push_message(uid, content)
    #       return 0
    #   elif re.match("Q2", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q2))
    #       line_bot_api.push_message(uid, questionnaire.Q2_menu())
    #       return 0
    #   elif re.match("Q3", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q3))
    #       line_bot_api.push_message(uid, questionnaire.Q3_menu())
    #       return 0
    #   elif re.match("Q4", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q4))
    #       line_bot_api.push_message(uid, questionnaire.Q4_menu())
    #       return 0
    #   elif re.match("Q5", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q5))
    #       line_bot_api.push_message(uid, questionnaire.Q5_menu())
    #       return 0
    #   elif re.match("Q6", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q6))
    #       line_bot_api.push_message(uid, questionnaire.Q6_menu())
    #       return 0
    #   elif re.match("Q7", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q7))
    #       line_bot_api.push_message(uid, questionnaire.Q7_menu())
    #       return 0
    #   elif re.match("Q8", msg):
    #       line_bot_api.push_message(uid, TextSendMessage(questionnaire.Q8))
    #       line_bot_api.push_message(uid, questionnaire.Q8_menu())
    #       return 0
    #   elif re.match("類型A", msg):
    #       img_url = questionnaire.type_A
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型B", msg):
    #       img_url = questionnaire.type_B
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型B", msg):
    #       img_url = questionnaire.type_B
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型C", msg):
    #       img_url = questionnaire.type_C
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型D", msg):
    #       img_url = questionnaire.type_D
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型E", msg):
    #       img_url = questionnaire.type_E
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型F", msg):
    #       img_url = questionnaire.type_F
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型G", msg):
    #       img_url = questionnaire.type_G
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型H", msg):
    #       img_url = questionnaire.type_H
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型I", msg):
    #       img_url = questionnaire.type_I
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #   elif re.match("類型J", msg):
    #       img_url = questionnaire.type_J
    #       line_bot_api.push_message(uid, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url))
    #       return 0
    #==========================================
    #   elif re.match("新書榜", msg):
    #       line_bot_api.push_message(uid, TextSendMessage("將給您最新理財新書......"))
    #       flex_message = Msg_Template.new_books()
    #       line_bot_api.push_message(uid, flex_message)
    #       return 0
    #   elif re.match("暢銷榜", msg):
    #       line_bot_api.push_message(uid, TextSendMessage("將給您最新理財暢銷書......"))
    #       flex_message = Msg_Template.famous_books()
    #       line_bot_api.push_message(uid, flex_message)
    #       return 0
    #==========================================
    if re.match("/股票", msg):
        content = Msg_Template.menu_stock_msg
        line_bot_api.push_message(uid, TextSendMessage(content))
        content = Msg_Template.menu_etf_msg
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("/理財", msg):
        content = Msg_Template.menu_fin_msg
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("外匯列表", msg):
        content = Msg_Exrate.realtime_menu()
        line_bot_api.push_message(uid, content)
        return 0
    elif re.match("/外匯", msg):
        content = Msg_Template.menu_exrate_msg
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("/我的收藏", msg):
        content = Msg_Template.menu_mylist_msg
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("#股票健診", msg):
        content = Msg_diagnose.diagnose_menu()
        line_bot_api.push_message(uid, content)
        return 0
#   elif re.match("/產業文章", msg):
#       content = Msg_Template.industrial_artical()
#       line_bot_api.push_message(uid, content)
#        return 0
#   elif re.match("理財YOUTUBER推薦", msg):
#       content = Msg_Template.youtube_channel()
#       line_bot_api.push_message(uid, content)
#       return 0
#===========================================
    elif re.match('關注[0-9]{4}', msg):  # 使用者新增股票至股票清單
        stockNumber = msg[2:6]
        stockName = stockprice.get_stock_name(stockNumber)
        if stockName == "no": content = "股票代碼錯誤"
        else:
            line_bot_api.push_message(uid,
                                      TextSendMessage("加入股票代號" + stockNumber))
            if re.match('關注[0-9]{4}[<>][0-9]', msg):
                content = mongodb.write_my_stock(uid, user_name, stockNumber,
                                                 msg[6:7], msg[7:])
            else:
                content = mongodb.write_my_stock(uid, user_name, stockNumber,
                                                 "未設定", "未設定")
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
#   elif re.match("股票教學", msg):
#       content = Msg_Template.stock_info_menu()
#       line_bot_api.push_message(uid, content)
#       return 0
#   elif re.match("外匯教學", msg):
#       content = Msg_Exrate.Exrate_msg
#       line_bot_api.push_message(uid, TextSendMessage(content))
#       return 0
#   elif re.match("快樂學理財", msg):
#       content = Msg_Template.learning_menu()
#       line_bot_api.push_message(uid, content)
#       return 0
    elif re.match("三大投資分析表", msg):
        img_url = "https://i.imgur.com/StGNRGR.png"
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=img_url,
                             preview_image_url=img_url))
        return 0
    elif re.match("基本面", msg):
        content = Msg_Template.three_investment(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("技術面", msg):
        content = Msg_Template.three_investment(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("籌碼面", msg):
        content = Msg_Template.three_investment(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("保守型投資者", msg):
        content = Msg_Template.investor_type(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("激進型投資者", msg):
        content = Msg_Template.investor_type(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("獨立型投資者", msg):
        content = Msg_Template.investor_type(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("EPS", msg):
        content = Msg_Template.proper_noun(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("買超/賣超", msg):
        content = Msg_Template.proper_noun(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("多頭市場/空頭市場", msg):
        content = Msg_Template.proper_noun(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("黃金交叉/死亡交叉", msg):
        content = Msg_Template.proper_noun(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0

#   elif re.match("理財電影", msg):
#       content =Msg_Template.movies()
#        line_bot_api.push_message(uid, content)
#       return 0
#   elif re.match("理財書籍", msg):
#       content = Msg_Template.fin_books()
#       line_bot_api.push_message(uid, content)
#       return 0
    elif re.match("比較", msg):  # 範例 : msg = '比較2330/2002/2317'
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 我們將會給您這幾檔股票收盤價走勢圖...'))
        img_url = stock_compare.show_pic(msg)
        if img_url == "no":
            line_bot_api.push_message(uid, TextSendMessage('股票代碼錯誤'))
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=img_url,
                             preview_image_url=img_url))
    elif re.match('#[0-9]', msg):  #查詢某檔股票
        stockNumber = msg[1:]
        stockName = stockprice.get_stock_name(stockNumber)
        if stockName == "no":
            line_bot_api.push_message(uid, TextSendMessage("股票代碼錯誤"))
        else:
            line_bot_api.push_message(
                uid, TextSendMessage('稍等一下, 查詢編號' + stockNumber + '的股價中...'))
            content_text = stockprice.getprice(stockNumber, msg)
            content = Msg_Template.stock_reply(stockNumber, content_text)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("三大面向分析[0-9]", msg):
        stockNumber = msg.strip("三大面向分析")
        content = Msg_Template.stock_ananlysis_menu(stockNumber)
        line_bot_api.push_message(uid, content)
        return 0
    elif re.match('股票技術面[0-9]', msg):
        stockNumber = msg.strip("股票技術面")
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 分析編號' + stockNumber + '的股價中...'))
        content = Msg_Template.stock_tec_analysis(stockNumber)
        line_bot_api.push_message(uid, content)
        return 0
    elif re.match('股票基本面[0-9]{4}', msg):
        stockNumber = msg.strip("股票基本面")
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 分析編號' + stockNumber + '基本面中...'))
        content = Msg_Template.stock_fundation_analysis(stockNumber)
        line_bot_api.push_message(uid, content)
        return 0
    elif re.match("經營能力[0-9]{4}", msg):
        stockNumber = msg.strip("經營能力")
        stockName = stockprice.get_stock_name(stockNumber)
        line_bot_api.push_message(
            uid, TextSendMessage("正在為您分析股票代號" + stockNumber + "的經營能力......"))
        if stockName == "no":
            content = "股票代碼錯誤"
            line_bot_api.push_message(uid, TextSendMessage(content))
        else:
            content = Msg_fundamental_ability.operating_ability(
                stockNumber, stockName)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("償債能力[0-9]{4}", msg):
        stockNumber = msg.strip("償債能力")
        stockName = stockprice.get_stock_name(stockNumber)
        line_bot_api.push_message(
            uid, TextSendMessage("正在為您分析股票代號" + stockNumber + "的償債能力......"))
        if stockName == "no":
            content = "股票代碼錯誤"
            line_bot_api.push_message(uid, TextSendMessage(content))
        else:
            content = Msg_fundamental_ability.debt_ability(
                stockNumber, stockName)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("獲利能力[0-9]{4}", msg):
        stockNumber = msg.strip("獲利能力")
        stockName = stockprice.get_stock_name(stockNumber)
        line_bot_api.push_message(
            uid, TextSendMessage("正在為您分析股票代號" + stockNumber + "的獲利能力......"))
        if stockName == "no":
            content = "股票代碼錯誤"
            line_bot_api.push_message(uid, TextSendMessage(content))
        else:
            content = Msg_fundamental_ability.profit_ability(
                stockNumber, stockName)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("排除地雷股健診", msg):
        line_bot_api.push_message(
            uid,
            TextSendMessage(u'\U0001F538' +
                            "請輸入地雷股+股票代碼,如「地雷股2002」,即可快速了解該個股是否值得投資!"))
        return 0
    elif re.match("定存股健診", msg):
        line_bot_api.push_message(
            uid,
            TextSendMessage(u'\U0001F538' +
                            "請輸入定存股+股票代碼,如「定存股2002」,即可快速了解該個股是否值得投資!"))
        return 0
    elif re.match("成長股健診", msg):
        line_bot_api.push_message(
            uid,
            TextSendMessage(u'\U0001F538' +
                            "請輸入成長股+股票代碼,如「成長股2002」,即可快速了解該個股是否值得投資!"))
        return 0
    elif re.match("便宜股健診", msg):
        line_bot_api.push_message(
            uid,
            TextSendMessage(u'\U0001F538' +
                            "請輸入便宜股+股票代碼,如「便宜股2002」,即可快速了解該個股是否值得投資!"))
        return 0
    elif re.match("地雷股[0-9]{4}", msg):
        stockNumber = msg[3:]
        line_bot_api.push_message(
            uid,
            TextSendMessage('稍等一下, 正在為您做股票編號' + stockNumber + '地雷股排除健診...'))
        stockName = stockprice.get_stock_name(stockNumber)
        if stockName == "no":
            line_bot_api.push_message(uid, TextSendMessage("股票代碼錯誤"))
        else:
            content = Msg_diagnose.mine_stock_menu(stockNumber, stockName)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("成長股[0-9]{4}", msg):
        stockNumber = msg[3:]
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 正在為您做股票編號' + stockNumber + '成長股健診...'))
        stockName = stockprice.get_stock_name(stockNumber)
        if stockName == "no":
            line_bot_api.push_message(uid, TextSendMessage("股票代碼錯誤"))
        else:
            content = Msg_diagnose.growth_stock_menu(stockNumber, stockName)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("定存股[0-9]{4}", msg):
        stockNumber = msg[3:]
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 正在為您做股票編號' + stockNumber + '定存股健診...'))
        stockName = stockprice.get_stock_name(stockNumber)
        if stockName == "no":
            line_bot_api.push_message(uid, TextSendMessage("股票代碼錯誤"))
        else:
            content = Msg_diagnose.fixed_deposit_stock_menu(
                stockNumber, stockName)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("便宜股[0-9]{4}", msg):
        stockNumber = msg[3:]
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 正在為您做股票編號' + stockNumber + '便宜股健診...'))
        stockName = stockprice.get_stock_name(stockNumber)
        if stockName == "no":
            line_bot_api.push_message(uid, TextSendMessage("股票代碼錯誤"))
        else:
            content = Msg_diagnose.cheap_stock_menu(stockNumber, stockName)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match('ETF技術面[0-9]', msg):
        stockNumber = msg.strip("ETF技術面")
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 分析ETF編號' + stockNumber + '的股價中...'))
        content = Msg_Template.etf_tec_analysis(stockNumber)
        line_bot_api.push_message(uid, content)
        return 0
    elif re.match('ETF基本面[0-9]', msg):
        stockNumber = msg.strip("ETF基本面")
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 分析ETF編號' + stockNumber + '的股價中...'))
        content = Msg_Template.etf_fundation_analysis(stockNumber)
        line_bot_api.push_message(uid, content)
        return 0
    elif re.match("MACD[0-9]", msg):
        stockNumber = msg[4:]
        content = Msg_Template.macd_msg
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 將給您編號' + stockNumber + ' MACD指標...'))
        line_bot_api.push_message(uid, TextSendMessage(content))
        MACD_imgurl = Technical_Analysis.MACD_pic(stockNumber, msg)
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=MACD_imgurl,
                             preview_image_url=MACD_imgurl))
        btn_msg = Msg_Template.stock_reply_other(stockNumber)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    elif re.match('RSI[0-9]', msg):
        stockNumber = msg[3:]
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 將給您編號' + stockNumber + ' RSI指標...'))
        RSI_imgurl = Technical_Analysis_test.stock_RSI(stockNumber)
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=RSI_imgurl,
                             preview_image_url=RSI_imgurl))
        btn_msg = Msg_Template.stock_reply_other(stockNumber)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    elif re.match("BBAND[0-9]", msg):
        stockNumber = msg[5:]
        content = Msg_Template.bband_msg
        line_bot_api.push_message(uid, TextSendMessage(content))
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 將給您編號' + stockNumber + ' BBand指標...'))
        BBANDS_imgurl = Technical_Analysis.BBANDS_pic(stockNumber, msg)
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=BBANDS_imgurl,
                             preview_image_url=BBANDS_imgurl))
        btn_msg = Msg_Template.stock_reply_other(stockNumber)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    elif re.match('F[0-9]', msg):
        stockNumber = msg[1:]
        line_bot_api.push_message(
            uid, TextSendMessage('稍等一下, 將給您編號' + stockNumber + '三大法人買賣資訊...'))
        content = Institutional_Investors.institutional_investors(stockNumber)
        line_bot_api.push_message(uid, TextSendMessage(content))
        btn_msg = Msg_Template.stock_reply_other(stockNumber)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    elif re.match('刪除[0-9]{4}', msg):  # 刪除存在資料庫裡面的股票
        content = mongodb.delete_my_stock(user_name, msg[2:])
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('清空股票', msg):  # 刪除存在資料庫裡面的股票
        content = mongodb.delete_my_allstock(user_name, uid)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('我的股票', msg):  # 股票清單報價
        line_bot_api.push_message(uid, TextSendMessage('稍等一下, 股票查詢中...'))
        content = mongodb.show_my_stock(uid, user_name, msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('股票清單', msg):  # 查詢股票篩選條件清單
        line_bot_api.push_message(uid, TextSendMessage('稍等一下, 股票查詢中...'))
        content = mongodb.show_stock_setting(user_name, uid)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("P[0-9]{4}", msg):
        stockNumber = msg[1:]
        line_bot_api.push_message(uid, TextSendMessage('稍等一下, 股價走勢繪製中...'))
        trend_imgurl = stockprice.stock_trend(stockNumber, msg)
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=trend_imgurl,
                             preview_image_url=trend_imgurl))
        btn_msg = Msg_Template.stock_reply_other(stockNumber)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    elif re.match("K[0-9]{4}", msg):
        stockNumber = msg[1:]
        content = Msg_Template.kchart_msg + "\n" + Msg_Template.kd_msg
        line_bot_api.push_message(uid, TextSendMessage(content))
        line_bot_api.push_message(uid, TextSendMessage('稍等一下, K線圖繪製中...'))
        k_imgurl = kchart.draw_kchart(stockNumber)
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=k_imgurl,
                             preview_image_url=k_imgurl))
        btn_msg = Msg_Template.stock_reply_other(stockNumber)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    #--------------------------- 籌碼面分析 ---------------------------------------
    elif re.match('股票籌碼面[0-9]', msg):
        targetStock = msg[5:]
        line_bot_api.push_message(
            uid, TextSendMessage('分析' + targetStock + '籌碼面中,稍等一下。'))
        # 推撥籌碼面分析圖
        imgurl2 = Institutional_Investors.institutional_investors_pic(
            targetStock)
        if imgurl2 == "股票代碼錯誤!":
            line_bot_api.push_message(uid, TextSendMessage("股票代碼錯誤!"))
            return 0
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=imgurl2,
                             preview_image_url=imgurl2))
        btn_msg = Msg_Template.stock_reply_other(targetStock)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    # 個股年收益率
    elif re.match('收益率[0-9]', msg):
        targetStock = msg[3:]
        line_bot_api.push_message(
            uid, TextSendMessage('分析' + targetStock + '中,稍等一下。'))
        imgurl2 = stockprice.show_return(targetStock, msg)  # 收益率分析圖
        line_bot_api.push_message(
            uid,
            ImageSendMessage(original_content_url=imgurl2,
                             preview_image_url=imgurl2))
        btn_msg = Msg_Template.stock_reply_other(targetStock)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    elif re.match('外幣[A-Z]{3}', msg):
        currency = msg[2:5]  # 外幣代號
        currency_name = EXRate.getCurrencyName(currency)
        if currency_name == "無可支援的外幣":
            content = "無可支援的外幣"
            line_bot_api.push_message(uid, TextSendMessage(content))
        else:
            line_bot_api.push_message(
                uid, TextSendMessage('您要查詢的外幣是' + currency_name))
            text_message = EXRate.showCurrency(currency)
            content = Msg_Exrate.realtime_currency(text_message, currency)
            line_bot_api.push_message(uid, content)
        return 0
    elif re.match("CT[A-Z]{3}", msg):
        currency = msg[2:5]  # 外幣代號
        if EXRate.getCurrencyName(currency) == "無可支援的外幣":
            line_bot_api.push_message(uid, TextSendMessage('無可支援的外幣'))
            return 0
        line_bot_api.push_message(uid, TextSendMessage('稍等一下, 將會給您匯率走勢圖'))
        cash_imgurl = EXRate.cash_exrate_sixMonth(currency)
        if cash_imgurl == "現金匯率無資料可分析":
            line_bot_api.push_message(uid, TextSendMessage('現金匯率無資料可分析'))
        else:
            line_bot_api.push_message(
                uid,
                ImageSendMessage(original_content_url=cash_imgurl,
                                 preview_image_url=cash_imgurl))

        spot_imgurl = EXRate.spot_exrate_sixMonth(currency)
        if spot_imgurl == "即期匯率無資料可分析":
            line_bot_api.push_message(uid, TextSendMessage('即期匯率無資料可分析'))
        else:
            line_bot_api.push_message(
                uid,
                ImageSendMessage(original_content_url=spot_imgurl,
                                 preview_image_url=spot_imgurl))
        btn_msg = Msg_Exrate.realtime_currency_other(currency)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    # 匯率查詢
    # 匯率換算(台銀)
    elif re.match("買入外幣[A-Z]{3}[0-9]", msg):
        currency = msg[4:7]
        currency_name = EXRate.getCurrencyName(currency)
        if currency_name == "無可支援的外幣": content = "無可支援的外幣"
        else:
            line_bot_api.push_message(uid, TextSendMessage("正在為您做外幣換算......"))
            content = EXRate.exchange_currency(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("賣出外幣[A-Z]{3}[0-9]", msg):
        currency = msg[4:7]
        currency_name = EXRate.getCurrencyName(currency)
        if currency_name == "無可支援的外幣": content = "無可支援的外幣"
        else:
            line_bot_api.push_message(uid, TextSendMessage("正在為您做外幣換算......"))
            content = EXRate.exchange_currency(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('新增外幣[A-Z]{3}', msg):
        currency = msg[4:7]
        currency_name = EXRate.getCurrencyName(currency)
        if currency_name == "無可支援的外幣": content = "無可支援的外幣"
        elif re.match('新增外幣[A-Z]{3}[<>][0-9]', msg):
            content = mongodb.write_my_currency(uid, user_name, currency,
                                                msg[7:8], msg[8:])
        else:
            content = mongodb.write_my_currency(uid, user_name, currency,
                                                "未設定", "未設定")

        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('刪除外幣[A-Z]{3}', msg):
        content = mongodb.delete_my_currency(user_name, msg[4:7])
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("換匯[A-Z]{3}/[A-Z{3}]", msg):
        line_bot_api.push_message(uid, TextSendMessage("將為您做外匯計算....."))
        content = EXRate.getExchangeRate(msg)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('清空外幣', msg):
        content = mongodb.delete_my_allcurrency(user_name, uid)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('我的外幣', msg):
        line_bot_api.push_message(uid, TextSendMessage('稍等一下, 匯率查詢中...'))
        content = mongodb.show_my_currency(uid, user_name)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match('外幣清單', msg):  # 查詢外幣篩選條件
        line_bot_api.push_message(uid, TextSendMessage('稍等一下, 外幣查詢中...'))
        content = mongodb.show_currency_setting(user_name, uid)
        line_bot_api.push_message(uid, TextSendMessage(content))
        return 0
    elif re.match("每週回顧", msg):
        line_bot_api.push_message(uid, TextSendMessage("我們將給您最新的周回顧"))
        line_bot_api.push_message(uid, Msg_News.weekly_finance_news())
        return 0
    elif re.match('N[0-9]{4}', msg):  # 個股新聞
        stockNumber = msg[1:5]
        content = Msg_News.single_stock(stockNumber)
        line_bot_api.push_message(
            uid, TextSendMessage('即將給您代號' + stockNumber + '個股新聞'))
        line_bot_api.push_message(uid, content)
        btn_msg = Msg_Template.stock_reply_other(stockNumber)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    elif re.match("N外匯[A-Z]{3}", msg):
        currency = msg[3:6]
        line_bot_api.push_message(uid, TextSendMessage("將給您最新外匯消息"))
        line_bot_api.push_message(uid, Msg_News.exrate_news())
        btn_msg = Msg_Exrate.realtime_currency_other(currency)
        line_bot_api.push_message(uid, btn_msg)
        return 0
    else:
        line_bot_api.push_message(uid, TextSendMessage('尚未讀取到'))
        return 0