Ejemplo n.º 1
0
def handle_image(event):
    print("handle_image:", event)

    message_id = event.message.id
    message_content = line_bot_api.get_message_content(message_id)

    image = BytesIO(message_content.content)
    ###
    image_url = 'https://api.line.me/v2/bot/message/' + message_id + '/content/'
    print(image_url)
    getImageLine(message_id)
    print(getImageLine(message_id))
    ###

    try:
        image_text = get_text_by_ms(image_url=getImageLine(message_id),image=image)

        messages = [
            TextSendMessage(text=image_text),
        ]

        reply_message(event, messages)

    except Exception as e:
        reply_message(event, TextSendMessage(text='エラーが発生しました'))
Ejemplo n.º 2
0
def img(message, params):
    #ファイル添付があった場合
    if 'file' in message.body:
        url = message.body['file']['url_private']
        flag = message.body['file']['filetype']
        tmpfile = "./tmp." + flag

        if (flag not in ["jpg", "jpeg", "png", "gif"]):
            return

        message.send("文字起こし中…")

        #添付ファイルを一旦ローカルに保存
        rst = requests.get(url,
                           headers={'Authorization': 'Bearer %s' % API_TOKEN},
                           stream=True)
        fo = open(tmpfile, "wb")
        shutil.copyfileobj(rst.raw, fo)
        fo.close()

        #API利用
        with open(tmpfile, 'rb') as f:
            data = f.read()

        message_text = get_text_by_ms(data)
        os.remove(tmpfile)
        message.send(message_text)
Ejemplo n.º 3
0
def handle_message(event):
    print("handle_message:", event)
    text = event.message.text

    if (text.startswith('http')):
        image_text = get_text_by_ms(text)
        messages = [
            TextSendMessage(text=image_text),
        ]

    else:
        messages = [
            TextSendMessage(text=text),
            TextSendMessage(text='画像を送信するか、画像のURLを送ってみてね!'),
        ]

    reply_message(event, messages)
Ejemplo n.º 4
0
def handle_image(event):
    print("handle_image:", event)

    message_id = event.message.id
    message_content = line_bot_api.get_message_content(message_id)

    image = BytesIO(message_content.content)

    try:
        image_text = get_text_by_ms(image=image)

        messages = [
            TextSendMessage(text=image_text),
        ]

        reply_message(event, messages)

    except Exception as e:
        reply_message(event, TextSendMessage(text='エラーが発生しました'))