Exemplo n.º 1
0
def res_user_status(event):
	profile = line_bot_api.get_profile(event.source.user_id)
	status_msg = profile.status_message
	if status_msg != "None":
		# LINEに登録されているstatus_messageが空の場合は、"なし"という文字列を代わりの値とする
		status_msg = "なし"
	message=FlexSendMessage(
		alt_text='ユーザー情報',
		contents=BubbleContainer(
			header=BoxComponent(
				layout="vertical",
				contents=[
					TextComponent(
						text='text',
						align='center',
						gravity='center',
						contents=[
							SpanComponent(text='ユーザー情報')
						]
					)
				]
			),#Header
			hero=ImageComponent(
				url=profile.picture_url,
				size="full",
				aspect_mode="fit",
				action=None
			),
			body=BoxComponent(
				layout="vertical",
				contents=[
					TextComponent(
						text='text',
						align='center',
						gravity='center',
						contents=[
							SpanComponent(text=f'User Id: {profile.user_id}')
						]
					),
					TextComponent(
						text='text',
						align='center',
						gravity='center',
						contents=[
							SpanComponent(text=f'Status Message: {status_msg}')
						]
					)
				]
			),#Body
			footer=BoxComponent(
				layout="vertical",
				contents=[
					ButtonComponent(
						action=MessageAction(label="成功", text="?")
					)
				]
			)#Footer
		)
	)
	line_bot_api.reply_message(event.reply_token, messages=message)
Exemplo n.º 2
0
def getRate(rate):
    if rate < 0:
        return [
            TextComponent(text="RATING UNKNOW",
                          size='sm',
                          color='#aaaaaa',
                          flex=1,
                          margin='md')
        ]
    component = []
    _rate = int(rate)
    for i in range(_rate):
        component.append(
            IconComponent(
                size='sm',
                url=
                'https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png'
            ))
    for i in range(5 - _rate):
        component.append(
            IconComponent(
                size='sm',
                url=
                'https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png'
            ))
    component.append(
        TextComponent(text=str(rate),
                      size='sm',
                      color='#aaaaaa',
                      flex=1,
                      margin='md'))
    return component
def integer_word(word):
    content = look_up(word)
    if content != '查無此字':
        content = [
            TextComponent(text='🔍英文單字查詢',
                          weight='bold',
                          align='center',
                          size='md',
                          wrap=True,
                          color='#000000'),
            SeparatorComponent(margin='lg'),
            TextComponent(text=content, size='sm', wrap=True, color='#000000')
        ]
        audio_button = [
            SeparatorComponent(),
            ButtonComponent(style='link',
                            height='sm',
                            action=PostbackAction(
                                label='📢 美式發音', data='audio/{}'.format(word)))
        ]
        bubble = get_total_flex(content, audio_button)
        message = FlexSendMessage(alt_text="hello", contents=bubble)
    else:
        message = TextSendMessage(text=content)
    return message
Exemplo n.º 4
0
    def intro(self, name):

        bubble = BubbleContainer(

            # body
            body=BoxComponent(
                layout='vertical',
                spacing='md',
                contents=[
                    TextComponent(text='Hello {0},\n\n'.format(name), weight='bold', size='lg'),

                    # main info
                    TextComponent(text='我是呂明聲,現在就讀中央資管所碩一,熱愛開發、嘗試新技術,喜歡透過資訊科技解決問題 !\n\n如履歷所述,我曾擔任過資源教室助教及銀行資訊部實習生,喜歡協助同學也喜歡團隊合作解決問題,相信是TechFRESH不可或缺的Hack, everything 精神 !\n\n很高興能在這相遇,期望這是我們認識的開始!\n\nRegards,\nMing-Sheng,Lyu', size='md', wrap=True, color='#272727'),

                    SeparatorComponent(margin='xl'),

                    BoxComponent(
                        layout = 'vertical',
                        contents = [
                        SpacerComponent(size='md'),
                        ButtonComponent(
                            style='primary',
                            height='sm',
                            action=MessageAction(label="SAM's Skill", text='你會什麼?'),
                            )                                                                  
                        ]
                    )
                ]
            )
        )
        message = FlexSendMessage(alt_text="SAM's Intro", contents=bubble)
        return message
Exemplo n.º 5
0
 def test_bubble_container(self):
     arg = {
         'header':
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Header text')]),
         'body':
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Body text')]),
         'footer':
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Footer text')]),
         'styles':
         BubbleStyle(header=BlockStyle(background_color='#00ffff'),
                     hero=BlockStyle(background_color='#00ffff',
                                     separator=True),
                     footer=BlockStyle(background_color='#00ffff',
                                       separator=True,
                                       separator_color='#00ffff'))
     }
     heros = [
         ImageComponent(uri='https://example.com/flex/images/image.jpg'),
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Body text')]),
     ]
     for hero in heros:
         arg['hero'] = hero
         self.assertEqual(self.serialize_as_dict(arg, type=self.BUBBLE),
                          BubbleContainer(**arg).as_json_dict())
Exemplo n.º 6
0
 def test_carousel_container(self):
     arg = {
         'contents': [
             BubbleContainer(body=BoxComponent(
                 layout='vertical', contents=[TextComponent(text='Hey')])),
             BubbleContainer(body=BoxComponent(
                 layout='vertical', contents=[TextComponent(text='Foo')])),
         ]
     }
     self.assertEqual(self.serialize_as_dict(arg, type=self.CAROUSEL),
                      CarouselContainer(**arg).as_json_dict())
Exemplo n.º 7
0
 def get_open_now(open_now):
     if open_now is None:
         return FillerComponent()
     if open_now:
         return TextComponent(text="Buka",
                              size="sm",
                              margin="xs",
                              color="#1DB446")
     else:
         return TextComponent(text="Tutup",
                              size="sm",
                              margin="xs",
                              color="#ff334b")
Exemplo n.º 8
0
 def test_flex_message(self):
     arg = {
         'alt_text':
         'this is a flex message',
         'contents':
         BubbleContainer(body=BoxComponent(layout='vertical',
                                           contents=[
                                               TextComponent(text='hello'),
                                               TextComponent(text='world')
                                           ]))
     }
     self.assertEqual(self.serialize_as_dict(arg, type=self.FLEX),
                      FlexSendMessage(**arg).as_json_dict())
Exemplo n.º 9
0
def createBubbleContainer(station_name, what_day, time1, time2, time3):
    bubble = BubbleContainer(
        direction="ltr",
        header=BoxComponent(layout="vertical",
                            contents=[
                                BoxComponent(layout="horizontal",
                                             contents=[
                                                 TextComponent(
                                                     text=station_name,
                                                     weight="bold"),
                                                 TextComponent(text=what_day)
                                             ])
                            ]),
        body=BoxComponent(layout="vertical",
                          contents=[
                              BoxComponent(layout="horizontal",
                                           contents=[
                                               TextComponent(text="↓Campus"),
                                               TextComponent(text=time1)
                                           ]),
                              BoxComponent(layout="horizontal",
                                           contents=[
                                               TextComponent(text="↓" +
                                                             station_name),
                                               TextComponent(text=time2)
                                           ]),
                              BoxComponent(layout="horizontal",
                                           contents=[
                                               TextComponent(text="↓Campus"),
                                               TextComponent(text=time3)
                                           ])
                          ]),
        styles=BubbleStyle(body=BlockStyle(separator=True)))
    return bubble
Exemplo n.º 10
0
 def create_response(self):
     contents = [
         TextComponent(text=self._context['text'], wrap=True, size='sm'),
         SeparatorComponent()
     ]
     for index, name in enumerate(self._context['trash_list']):
         contents.append(
             TextComponent(text=name,
                           color='#0000ff',
                           wrap=True,
                           action=MessageAction(text=name)))
     return FlexSendMessage(
         alt_text=self._context['text'],
         contents=BubbleContainer(body=BoxComponent(
             layout='vertical', contents=contents, spacing='md')))
Exemplo n.º 11
0
def generate_carousel_for_search(books):
    contents = []
    for book in books:
        content = BubbleContainer(
            action=URIAction(uri=book['url']),
            size='micro',
            hero=ImageComponent(url=book['photo_url'],
                                size='full',
                                aspect_mode='cover',
                                aspect_ratio='320:213'),
            body=BoxComponent(layout='vertical',
                              spacing='sm',
                              padding_all='13px',
                              contents=[
                                  TextComponent(text=book['name'],
                                                weight='bold',
                                                size='sm'),
                                  BoxComponent(
                                      layout='baseline',
                                      contents=[
                                          TextComponent(text=book['authors'],
                                                        size='xs',
                                                        color='#8c8c8c',
                                                        margin='md'),
                                          TextComponent(text=book['publisher'],
                                                        size='xs',
                                                        color='#8c8c8c',
                                                        margin='md')
                                      ]),
                                  SeparatorComponent(margin='md',
                                                     color='#a0a0a0'),
                                  TextComponent(text=book['summary'],
                                                color='#8c8c8c',
                                                size='xs',
                                                wrap=True)
                              ]),
            footer=BoxComponent(layout='vertical',
                                contents=[
                                    SeparatorComponent(margin='md',
                                                       color='#a0a0a0'),
                                    TextComponent(text=book['price'],
                                                  wrap=True,
                                                  size='sm',
                                                  flex=5,
                                                  align='center')
                                ]))
        contents.append(content)
    return CarouselContainer(contents=contents)
Exemplo n.º 12
0
    def intro(self, user_name):
        bubble = BubbleContainer(
            # header
            header=BoxComponent(layout='horizontal',
                                contents=[
                                    TextComponent(
                                        text='Hi {0},'.format(user_name),
                                        size='lg',
                                        color='#000000')
                                ]),

            # hero
            hero=ImageComponent(url='https://i.imgur.com/xYgkKHe.png',
                                size='full',
                                aspect_ratio='16:9',
                                aspect_mode='cover'),

            # body
            body=BoxComponent(
                layout='vertical',
                spacing='md',
                contents=[
                    SeparatorComponent(margin='md'),
                    BoxComponent(
                        layout='horizontal',
                        spacing='md',
                        contents=[
                            TextComponent(
                                text='Hi 可以發一張圖片給我,\n我能識別出裡面的人臉情緒唷~\n\n',
                                size='md',
                                wrap=True,
                                color='#272727',
                                align='center')
                        ]),
                    BoxComponent(
                        layout='horizontal',
                        spacing='md',
                        contents=[
                            TextComponent(
                                text='聲明\n辨識完即刪除,不會以任何形式保存圖片、人像等敏感性資訊',
                                size='sm',
                                wrap=True,
                                color='#00BE00',
                                align='center')
                        ])
                ]))
        message = FlexSendMessage(alt_text="hello~", contents=bubble)
        return message
Exemplo n.º 13
0
 def show_single_result(self, imgurl, emotion, confidence):
     bubble = BubbleContainer(
         # header
         header=BoxComponent(layout='horizontal',
                             contents=[
                                 TextComponent(text='辨識結果',
                                               size='lg',
                                               color='#5b5b5b')
                             ]),
         #hero
         hero=ImageComponent(url='{0}'.format(imgurl),
                             size='3xl',
                             aspect_ratio='16:9',
                             aspect_mode='fit'),
         # body
         body=BoxComponent(
             layout='vertical',
             spacing='md',
             contents=[
                 SeparatorComponent(margin='md'),
                 BoxComponent(layout='horizontal',
                              spacing='md',
                              contents=[
                                  TextComponent(text='情緒 :',
                                                size='lg',
                                                color='#9d9d9d',
                                                align='center'),
                                  TextComponent(text='{0}'.format(emotion),
                                                size='lg',
                                                color='#00BE00',
                                                weight='bold')
                              ]),
                 BoxComponent(layout='horizontal',
                              spacing='md',
                              contents=[
                                  TextComponent(text='信心值 :',
                                                size='lg',
                                                color='#9d9d9d',
                                                align='center'),
                                  TextComponent(
                                      text='{0}%'.format(confidence),
                                      size='lg',
                                      color='#00BE00',
                                      weight='bold')
                              ])
             ]))
     message = FlexSendMessage(alt_text="辨識結果", contents=bubble)
     return message
Exemplo n.º 14
0
def handle_Patient_Introduce(event):

    textlist = ['See coronavirus pneumonia patients distribution (Update to 3.27)', \
                'Check the distribution of patients in China in some day (must choose a date, provided 1.22-3.27)', \
                'View patients distribution in a country (must choose a date, provided 1.22-3.27)', \
                'Look patients distributionis in a province or region']

    questionlist = ['I want to know coronavirus pneumonia patients distribution.', \
                'How\'s patients distributionis in China in 3.23?', \
                'How\'s patients condition about US in 2.24?', \
                'How\'s patients distributionis in Hubei?']

    cont = []
    for i in range(4):
        row = BoxComponent(
            layout='baseline',
            spacing='sm',
            contents=[
                TextComponent(
                    text=textlist[i],
                    color='#666666',
                    size='sm',
                    margin='md',
                    wrap=True,
                    action=MessageTemplateAction(text=questionlist[i]))
            ],
        )
        cont.append(row)
        cont.append(SeparatorComponent())
    del (cont[-1])

    title = 'You could ask following four type questions:'
    bubble = BubbleContainer(direction='ltr',
                             body=BoxComponent(layout='vertical',
                                               contents=[
                                                   TextComponent(text=title,
                                                                 weight='bold',
                                                                 wrap=True,
                                                                 size='md'),
                                                   BoxComponent(
                                                       layout='vertical',
                                                       margin='lg',
                                                       spacing='sm',
                                                       contents=cont)
                                               ]))

    message = FlexSendMessage(alt_text="hello", contents=bubble)
    line_bot_api.reply_message(event.reply_token, message)
Exemplo n.º 15
0
def single(set1):
    for x in set1:
        mes = BubbleContainer(
            hero=ImageComponent(url=set1[x],
                                size='full',
                                align='center',
                                aspect_ratio='13:13',
                                aspect_mode='cover'),
            body=BoxComponent(layout='vertical',
                              contents=[
                                  TextComponent(margin='md',
                                                text=x,
                                                weight='bold',
                                                size='md',
                                                align='center'),
                                  SeparatorComponent(margin='xl',
                                                     color='#0000FF'),
                                  BoxComponent(margin='md',
                                               layout='horizontal',
                                               spacing='xs',
                                               contents=[
                                                   ButtonComponent(
                                                       style='link',
                                                       color='#84C1FF',
                                                       flex=1,
                                                       height='sm',
                                                       action=MessageAction(
                                                           label="我的最愛",
                                                           text='SeeMyLove'))
                                               ])
                              ]))
        return FlexSendMessage(alt_text="hello", contents=mes)
    else:
        return TextSendMessage(text="None img")
Exemplo n.º 16
0
def price():
    mes = BubbleContainer(
        header=BoxComponent(layout='baseline',
                            contents=[
                                TextComponent(text='Q5:價格預算',
                                              weight='bold',
                                              size='xxl',
                                              flex=2,
                                              align='center')
                            ]),
        body=BoxComponent(
            layout='vertical',
            spacing='xs',
            contents=[
                ButtonComponent(style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='100~350元',
                                                     text='100~350元')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='351~600元',
                                                     text='351~600元')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='600元以上',
                                                     text='600元以上'))
            ]))
    message = FlexSendMessage(alt_text="hello", contents=mes)
    return message
Exemplo n.º 17
0
def get_greeting_carousel(parts: list):
    buttons = []
    elements = []
    for i, part in enumerate(parts):
        elements.append(
            ButtonComponent(color='#097AC5',
                            action=MessageAction(label=part, text=part)))
        if i % 2 == 1:
            buttons.append(
                BoxComponent(layout="horizontal",
                             color='#097AC5',
                             contents=list(elements)))
            elements = []

    return CarouselContainer(contents=[
        BubbleContainer(
            size='mega',
            body=BoxComponent(
                layout="vertical",
                background_color='#f8f8f8',
                contents=[
                    TextComponent(
                        align='start',
                        color='#222E38',
                        text=
                        '😇If wanna know me more, please click your interested section below!',
                        size='md',
                        weight='regular',
                        wrap=True)
                ]),
            footer=BoxComponent(layout="vertical",
                                padding_all='none',
                                background_color='#F8F8F8',
                                contents=list(buttons)))
    ])
Exemplo n.º 18
0
def add_video(template, title, url, thumbnails):
    bubble = BubbleContainer(
        direction='ltr',
        hero=ImageComponent(url=thumbnails,
                            size='full',
                            aspect_ratio='20:13',
                            aspect_mode='cover',
                            gravity='center'),
        body=BoxComponent(
            layout='vertical',
            contents=[
                # title
                TextComponent(text=title,
                              wrap=True,
                              weight='bold',
                              size='xxl',
                              align='center')
            ]),
        footer=BoxComponent(layout='vertical',
                            spacing='sm',
                            contents=[
                                SpacerComponent(size='sm'),
                                ButtonComponent(
                                    style='link',
                                    height='sm',
                                    action=URIAction(label='點擊查看', uri=url),
                                )
                            ]),
    )
    template.contents.append(bubble)
    return template
Exemplo n.º 19
0
def build_rabbit_adopt_content():
    container = BubbleContainer(
        direction='ltr',
        body=BoxComponent(
            layout='vertical',
            contents=[
                TextComponent(text='你還沒有兔子', weight='bold', size='xl'),
                SeparatorComponent(),
                BoxComponent(layout='horizontal',
                             spacing='sm',
                             contents=[
                                 ButtonComponent(
                                     style='primary',
                                     height='sm',
                                     color='#95B9B4',
                                     action=MessageAction(label='領養兔子',
                                                          text='領養兔子'),
                                 ),
                                 ButtonComponent(style='primary',
                                                 height='sm',
                                                 color='#95B9B4',
                                                 action=MessageAction(
                                                     label='沒事了', text='沒事了'))
                             ])
            ],
        ),
    )
    return container
Exemplo n.º 20
0
def construct_multiple_choice(data):
    actions = []
    for button in data.get("buttons"):
        actions.append(
            ButtonComponent(
                style="primary",
                height="sm",
                margin="md",
                action=MessageAction(label=button.get("title"),
                                     text=button.get("title")),
            ))

    bubble = BubbleContainer(
        direction="ltr",
        body=BoxComponent(
            layout="vertical",
            contents=construct_mc_header(data) + [
                TextComponent(
                    text=data.get("text"),
                    size="md",
                    margin="lg",
                    wrap=True,
                )
            ],
        ),
        footer=BoxComponent(layout="vertical", contents=actions),
    )

    return bubble
Exemplo n.º 21
0
def chain():
    mes = BubbleContainer(
        header=BoxComponent(layout='baseline',
                            contents=[
                                TextComponent(text='Q4:想購買的通路',
                                              weight='bold',
                                              size='xxl',
                                              flex=2,
                                              align='center')
                            ]),
        body=BoxComponent(
            layout='vertical',
            spacing='xs',
            contents=[
                ButtonComponent(style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='家樂福', text='家樂福')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='全聯', text='全聯')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='Costco',
                                                     text='Costco'))
            ]))
    message = FlexSendMessage(alt_text="hello", contents=mes)
    return message
Exemplo n.º 22
0
def feedback(event):
    bubble = BubbleContainer(direction='ltr',
    body=BoxComponent(layout='vertical',
        contents=[
                # title
                TextComponent(text='笑話回饋', weight='bold', size='xl'),
                # info
                BoxComponent(layout='vertical', margin='lg', spacing='sm',
                    contents=[
                        BoxComponent(layout='baseline', spacing='sm',
                            contents=[
                                TextComponent(
                                    text='請問您覺得這個笑話好笑嗎?',
                                    color='#aaaaaa',
                                    size='sm',
                                    flex=1
                                ),
                            ],
                        )
                    ],
                    )
        ],),
    footer=BoxComponent(layout='vertical', spacing='sm',
        contents=[
            # callAction
            ButtonComponent(
                style='link',
                height='sm',
                action=MessageAction(label='好笑', text= '好笑'),
            ),
            ButtonComponent(
                style='link',
                height='sm',
                action=MessageAction(label='有點好笑', text= '有點好笑'),
            ),
            ButtonComponent(
                style='link',
                height='sm',
                action=MessageAction(label='不好笑', text= '不好笑'),
            ),

        ]
    ),
    )
    message = FlexSendMessage(alt_text="笑話回饋", contents=bubble)
    return message
Exemplo n.º 23
0
def aroma():
    mes = BubbleContainer(
        header=BoxComponent(layout='baseline',
                            contents=[
                                TextComponent(text='Q2:喜歡的香氣',
                                              weight='bold',
                                              size='xxl',
                                              flex=2,
                                              align='center')
                            ]),
        body=BoxComponent(
            layout='vertical',
            spacing='xs',
            contents=[
                ButtonComponent(style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='花香 (ex:玫瑰花...)',
                                                     text='花香')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='漿果 (ex:櫻桃...)',
                                                     text='漿果')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='柑橘 (ex:檸檬...)',
                                                     text='柑橘')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='熱帶水果 (ex:鳳梨...)',
                                                     text='熱帶水果')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='淺色水果 (ex:杏桃...)',
                                                     text='淺色水果')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='香料 (ex:胡椒...)',
                                                     text='香料')),
                ButtonComponent(margin='xl',
                                style='secondary',
                                color='#FFEE99',
                                height='sm',
                                action=MessageAction(label='土木 (ex:橡木桶...)',
                                                     text='土木'))
            ]))
    message = FlexSendMessage(alt_text="hello", contents=mes)
    return message
Exemplo n.º 24
0
def test_template():
    conn = model.Conn()

    # get all subject by class_id
    query_select_subject = 'SELECT * FROM subject WHERE id = %s'
    conn.query(query_select_subject, '2')
    row_subject = conn.cursor.fetchone()

    # get all topic by subject_id
    query_select_topic = 'SELECT * FROM topic WHERE subject_id = %s'
    conn.query(query_select_topic, '1')
    rows_topic = conn.cursor.fetchall()
    if len(rows_topic) == 0:  # topic is empty
        line_bot_api.reply_message(event.reply_token,
                                   [TextMessage(text=constant.TOPIC_EMPTY)])
    else:  # topic exist
        contents = []
        for row in rows_topic:
            contents.append(
                BubbleContainer(
                    direction='ltr',
                    body=BoxComponent(
                        layout='vertical',
                        contents=[
                            TextComponent(text=str(row['name']),
                                          margin='md',
                                          size='xl',
                                          align='center',
                                          gravity='center',
                                          weight='bold'),
                            ButtonComponent(action=PostbackAction(
                                label='Belajar',
                                text='Belajar',
                                data='action=material_learn&subject_id=' +
                                str(row_subject['id']) + '&topic_id=' +
                                str(row['id']))),
                            ButtonComponent(action=PostbackAction(
                                label='Diskusi',
                                text='Diskusi',
                                data='action=material_discussion&subject_id=' +
                                str(row_subject['id']) + '&topic_id=' +
                                str(row['id']))),
                            ButtonComponent(action=PostbackAction(
                                label='Latihan Soal',
                                text='Latihan Soal',
                                data='action=material_quiz&subject_id=' +
                                str(row_subject['id']) + '&topic_id=' +
                                str(row['id'])))
                        ])))

        flex_message = FlexSendMessage(
            alt_text='Carousel Topik',
            contents=CarouselContainer(contents=contents))

        print('HERE, contents:', contents)
        print('HERE, flex_message:', flex_message)

        return 'OK'
Exemplo n.º 25
0
    def create_response(self):
        trashinfo = self._context['trash_info'][0]
        contents = [
            TextComponent(text=self._context['text'], wrap=True, size='sm'),
            SeparatorComponent(),
        ]
        if trashinfo['name'] != '':
            contents.append(
                TextComponent(text='名前', color='#a0a0a0', size='sm'))
            contents.append(
                TextComponent(text=trashinfo['name'], wrap=True, size='sm'))
        if trashinfo['category'] != '':
            contents.append(
                TextComponent(text='種類', color='#a0a0a0', size='sm'))
            contents.append(
                TextComponent(text=trashinfo['category'], wrap=True,
                              size='sm'))
        if trashinfo['note'] != '':
            contents.append(
                TextComponent(text='メモ', color='#a0a0a0', size='sm'))
            contents.append(
                TextComponent(text=trashinfo['note'], wrap=True, size='sm'))

        return FlexSendMessage(
            alt_text=self._context['text'],
            contents=BubbleContainer(body=BoxComponent(
                layout='vertical', contents=contents, spacing='md')))
Exemplo n.º 26
0
 def test_text_component(self):
     arg = {
         'text': 'Hello, World!',
         'size': 'xl',
         'weight': 'bold',
         'color': '#0000ff'
     }
     self.assertEqual(self.serialize_as_dict(arg, type=self.TEXT),
                      TextComponent(**arg).as_json_dict())
Exemplo n.º 27
0
 def create_response(self):
     contents = [
         TextComponent(text=self._context['text'], wrap=True, size='sm'),
         SeparatorComponent()
     ]
     for index, content in enumerate(self._context['contents']):
         contents.append(
             TextComponent(text=content['text'],
                           color=Colors['link'],
                           wrap=True,
                           action=PostbackAction(
                               data=content['postback'],
                               display_text=content['text'])))
     return FlexSendMessage(
         alt_text=self._context['text'],
         contents=BubbleContainer(body=BoxComponent(
             layout='vertical', contents=contents, spacing='md')))
     return TextSendMessage(text=self._context['text'])
Exemplo n.º 28
0
def FlexWeatherTemplate(city, url, w, aqiindex, uvi):
    return (FlexSendMessage(
        alt_text=city + "-天氣及空氣品質 Flex",
        contents=BubbleContainer(body=BoxComponent(
            layout="vertical",
            padding_all="0px",
            contents=[
                ImageComponent(url=url,
                               gravity="center",
                               margin="none",
                               size="full",
                               aspectRatio="1:1",
                               aspectMode="cover"),
                BoxComponent(
                    layout="vertical",
                    padding_all="20px",
                    position="absolute",
                    contents=[
                        TextComponent(text=city, size="xl"),
                        TextComponent(text=str(
                            datetime.datetime.now(pytz.timezone(
                                'Asia/Taipei')).strftime("%Y/%m/%d %H:%M")),
                                      size="xs"),
                        ImageComponent(url="https" +
                                       w.get_weather_icon_url()[4:],
                                       size="xxs",
                                       align="start"),
                        TextComponent(text=status2ct(w.get_status()),
                                      size="xxl",
                                      weight="bold"),
                        TextComponent(text=w.get_detailed_status(), size="xs"),
                        TextComponent(text="溫度: " + str(
                            round(
                                w.get_temperature(
                                    unit='celsius')['temp'], 1)) + "°C" +
                                      " 濕度: " + str(w.get_humidity()) + "%",
                                      size="xl"),
                        TextComponent(text="空氣品質: " + requests.get(
                            'https://data.epa.gov.tw/api/v1/aqx_p_432?api_key=9be7b239-557b-4c10-9775-78cadfc555e9&format=json&limit=1234'
                        ).json()['records'][aqiindex]['AQI'] + "(" + aqi2rate(
                            requests.get(
                                'https://data.epa.gov.tw/api/v1/aqx_p_432?api_key=9be7b239-557b-4c10-9775-78cadfc555e9&format=json&limit=100'
                            ).json()['records'][aqiindex]['AQI']) + ")"),
                        TextComponent(
                            text="紫外線: " +
                            str(round(float(uvi.json()['records'][0]
                                            ['UVI']))) + "(" +
                            uvi2rate(uvi.json()['records'][0]['UVI']) + ")"),
                        TextComponent(
                            text="風速: " +
                            str(round(w.get_wind()['speed'] * 18 / 5, 1)) +
                            "km/h")
                    ])
            ]))))
Exemplo n.º 29
0
def get_news_message(title, href, img, imghref, showinTilte):
    cont = []
    for i in range(len(title)):
        row = BoxComponent(
            layout='baseline',
            spacing='sm',
            contents=[
                TextComponent(text=title[i],
                              color='#666666',
                              size='sm',
                              margin='md',
                              wrap=True,
                              action=URIAction(label='WEBSITE', uri=href[i]))
            ],
        )
        cont.append(row)
        cont.append(SeparatorComponent())
    del (cont[-1])

    title = 'Top News' + showinTilte
    bubble = BubbleContainer(
        direction='ltr',
        hero=ImageComponent(url=img[0],
                            size='full',
                            aspect_ratio='20:13',
                            aspect_mode='cover',
                            action=URIAction(uri=imghref[0], label='label')),
        body=BoxComponent(
            layout='vertical',
            contents=[
                # title
                TextComponent(text=title, weight='bold', size='xl'),
                # info
                BoxComponent(
                    layout='vertical',
                    margin='lg',
                    spacing='sm',
                    contents=cont,
                )
            ],
        ))

    message = FlexSendMessage(alt_text="hello", contents=bubble)
    return message
Exemplo n.º 30
0
    def welcome(self):

        bubble = BubbleContainer(

            # header
            header=BoxComponent(
                layout='horizontal',
                contents=[
                    TextComponent(text='哆哆歡迎您', weight='bold', size='lg', color='#00BE00')
                ]
            ),

            #hero
            hero=ImageComponent(url='https://i.imgur.com/onXQU46.png', size='full', aspect_ratio='16:9', aspect_mode='cover'),
                

            # body
            body=BoxComponent(
                layout='vertical',
                spacing='md',
                contents=[
                    
                    # main info
                    TextComponent(text='嗨,我是哆哆,感謝您加我為好友,我會回答您的問題讓您更進一步了解明聲。讓我們開始吧!\n\n您可以直接輸入:\n\n可以介紹一下嗎?\n你會什麼?\n你有什麼作品?\n有拿過什麼認證嗎?\n\n當不知道如何使用時,請輸入help\n我會出來為您引導。', size='md', wrap=True, color='#6c6c6c'),

                    SeparatorComponent(margin='xl'),

                    BoxComponent(
                        layout = 'vertical',
                        contents = [
                        SpacerComponent(size='md'),
                        ButtonComponent(
                            style='primary',
                            height='sm',
                            action=MessageAction(label="Let's Start", text='可以介紹一下嗎?'),
                            )                                                                  
                        ]
                    )
                ]
            )
        )
        message = FlexSendMessage(alt_text="Welcome", contents=bubble)
        return message