Beispiel #1
0
def webhook():
    if request.method == 'POST':
        payload = request.json

        Reply_token = payload['events'][0]['replyToken']
        print(Reply_token)
        message = payload['events'][0]['message']['text']
        print(message)
        if 'หุ้น' in message :
            ITD = thaistock('ITD')
            Reply_messasge = 'ราคาหุ้น อิตาเลียนไทย ขณะนี้ : {}'.format(ITD)
            ReplyMessage(Reply_token,Reply_messasge,Channel_access_token)
        
        elif "btc" in message :
            Reply_messasge = 'ราคา BITCOIN ขณะนี้ : {}'.format(GET_BTC_PRICE())
            ReplyMessage(Reply_token,Reply_messasge,Channel_access_token)


        return request.json, 200

    elif request.method == 'GET' :
        return 'this is method GET!!!' , 200

    else:
        abort(400)
Beispiel #2
0
def webhook():
    if request.method == 'POST':
        payload = request.json

        Reply_token = payload['events'][0]['replyToken']
        print(Reply_token)
        message = payload['events'][0]['message']['text']
        print(message)
        if 'หุ้น' in message:
            ITD = thaistock('ITD')
            Reply_messasge = 'คำตอบ: ราคาหุ้น อิตาเลียนไทย ขณะนี้ : {}'.format(
                ITD)
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif 'btc' in message:
            Reply_messasge = 'คำตอบ: ราคา BITCOIN ขณะนี้ : {}'.format(
                GET_BTC_PRICE_02())
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif 'เป็นใคร' in message:
            Reply_messasge = 'แนะนำตัว: ยูซูรุเองค่ะ'
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif 'คือใคร' in message:
            Reply_messasge = 'แนะนำตัว: ยูซูรุเองค่ะ'
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif '55' in message:
            Reply_messasge = 'งุนงง: หัวเราะหาพ่อมึงหรอ'
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif 'คำสั่ง' in message:
            Reply_messasge = 'ชี้แจง: เช็คหุ้น พิมพ์ อะไรก็ได้ตามด้วย หุ้น หรือให้มีคำว่าหุ้นอยู่ในประโยค\n\n\nค้นหาอนิเมะ พิมพ์ ชื่อเรื่อง\n\n\nถามราคา BTC พิมพ์ btc'
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif name[0] in message:
            Reply_messasge = AnimeZone.format(name[0])
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif name[1] in message:
            Reply_messasge = AnimeZone.format(name[1])
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif name[2] in message:
            Reply_messasge = AnimeZone.format(name[2])
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        return request.json, 200

    elif request.method == 'GET':
        return 'this is method GET!!!', 200

    else:
        abort(400)
Beispiel #3
0
def webhook():
    if request.method == 'POST':
        payload = request.json
        print(payload)
        print()
        Reply_token = payload['events'][0]['replyToken']
        print(Reply_token)
        print()
        message = payload['events'][0]['message']['text']
        print('message:')
        print(message)
        print(type(message))
        print()
        dest = payload['destination']
        print(dest)
        print()
        R0 = payload['events'][0]
        print(R0)
        print()
        # use for elif "btc"
        aa = "Hello"
        # aa = ["Hello", "Every one"]
        # aa = ("tuple1", "2", 33)
        # aa = ["Hello", ("tuple1", "2", 33), ["lis2", 10, 233]]

        # user for else:
        bb = {"type": "text", "text": "Hello"}
        cc = {
            "type":
            "text",
            "text":
            "(cc)นายสมชาย น้อยเอี่ยม work from home ที่ เอกชัยแมนชั่น ถ.เอกชัย ต.แม่กลอง อ.เมือง สมุทรสงคราม"
        }

        dd = {
            "type": "flex",
            "altText": "Flex Message",
            "contents": {
                "type": "bubble",
                "direction": "ltr",
                "header": {
                    "type":
                    "box",
                    "layout":
                    "vertical",
                    "contents": [{
                        "type": "text",
                        "text": "Header",
                        "align": "center"
                    }]
                },
                "hero": {
                    "type": "image",
                    "url":
                    "https://developers.line.biz/assets/images/services/bot-designer-icon.png",
                    "size": "full",
                    "aspectRatio": "1.51:1",
                    "aspectMode": "fit"
                },
                "body": {
                    "type":
                    "box",
                    "layout":
                    "vertical",
                    "contents": [{
                        "type": "text",
                        "text": "Hello World",
                        "align": "center"
                    }]
                },
                "footer": {
                    "type":
                    "box",
                    "layout":
                    "horizontal",
                    "contents": [{
                        "type": "button",
                        "action": {
                            "type": "uri",
                            "label": "Button",
                            "uri": "https://linecorp.com"
                        }
                    }]
                }
            }
        }

        # data = demo_reader_jsonfile_todict()
        # data = dd

        if 'hun' in message:
            ITD = thaistock('ITD')
            Reply_messasge = 'ราคาหุ้น อิตาเลียนไทย ขณะนี้ : {}'.format(ITD)
            print('Re:' + Reply_messasge)
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        elif "btc" in message:
            # Reply_messasge = 'ราคา BITCOIN ขณะนี้ : {}'.format(GET_BTC_PRICE())
            aa = list_to_str(aa)
            # aa = tuple_to_str(aa)
            Reply_messasge = 'Btc:\n{}'.format(aa)
            print('Re:' + Reply_messasge)
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)
        else:
            data = openpy_630422(message)
            if data == 1:
                # data = demo_reader_jsonfile_todict()
                data = cc

            Reply_messasge = data
            print('Re:')
            print(Reply_messasge)
            print('data_type:')
            print(type(Reply_messasge))
            print()
            ReplyMessage(Reply_token, Reply_messasge, Channel_access_token)

        return request.json, 200

    elif request.method == 'GET':
        return 'this is method GET from Webhook!!!', 200
    else:
        abort(400)
Beispiel #4
0
def mystock(stock_name: str = 'AOT'):
    price = thaistock(stock_name)
    return price
Beispiel #5
0
def stock(stock_name: str):
    price = thaistock(stock_name)
    return price
Beispiel #6
0
c.setFont('F1', 30)
c.setFillColor(colors.black)
c.drawCentredString(105 * mm, 280 * mm, 'ราคาหุ้น (+)')
c.drawCentredString(105 * mm, 180 * mm, 'ราคาหุ้น (-)')
c.drawCentredString(105 * mm, 80 * mm, 'ราคาหุ้น (0)')
# ใส่ข้อความแบบ list

textlines = []  #ราคาบวก
textlines2 = []  #ราคาลบ
textlines3 = []  #ไม่เปลี่ยนแปลง

mystock = ['SCB', 'TMB', 'KBANK', 'KTB', 'CPALL', 'CPN', 'GULF', 'PTT', 'BBL']

for st in mystock:
    check = thaistock(st)
    txt = 'Stock: {} Price: {} Baht Change: {}'.format(st, check[1], check[2])
    if check[2][0] == '+':
        textlines.append(txt)
    elif check[2][0] == '-':
        textlines2.append(txt)
    else:
        textlines3.append(txt)

#Zone1
text = c.beginText(40 * mm, 260 * mm)
text.setFont('F1', 25)
text.setFillColor(colors.green)
for line in textlines:
    text.textLine(line)
c.drawText(text)