Ejemplo n.º 1
0
 def test_filler_component(self):
     arg = {
         'flex': 2
     }
     self.assertEqual(
         self.serialize_as_dict(arg, type=self.FILLER),
         FillerComponent(**arg).as_json_dict()
     )
Ejemplo n.º 2
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")
Ejemplo n.º 3
0
def construct_mc_header(data):
    question_number = data.get("question_number", None)
    if question_number is None:
        return [
            TextComponent(text="Pilih salah satu",
                          size="xs",
                          margin="xs",
                          color="#27ACB2")
        ]
    else:
        percentage = int(round(float(question_number) / 12 * 100))
        return [
            TextComponent(
                text="Progress : {} %".format(percentage),
                size="xs",
                margin="xs",
                color="#27ACB2",
            ),
            BoxComponent(
                layout="vertical",
                margin="sm",
                height="6px",
                background_color="#9FD8E3",
                corner_radius="2px",
                contents=[
                    BoxComponent(
                        layout="vertical",
                        height="6px",
                        corner_radius="2px",
                        width="{}%".format(percentage),
                        background_color="#0D8186",
                        contents=[FillerComponent()],
                    )
                ],
            ),
        ]
Ejemplo n.º 4
0
def history_flexMessage(userid,date):
    uri = host + "/nutritionweb/history/" + userid+"/look/0"
    results = userFood.objects.filter(userId=userid,date=date)
    length=len(results)
    def item_loop(length):
        item_list=list()
        iniitem = BoxComponent(

            background_color="#EA8244",
            layout='baseline',
            contents=[
                TextComponent(
                    type="text",
                    text="您於今日還沒有紀錄喔!!!!",
                    color="#FFFFFF",
                    size="xl",
                    wrap=True,
                    align="center",
                ),
            ]
        )
        if length == 0:
            item_list.append(iniitem)
        elif length>10:
            item = BoxComponent(
                background_color="#EA8244",
                layout='baseline',
                contents=[
                    TextComponent(
                        type="text",
                        text="您紀錄太多筆無法喔,可以點擊下方按鈕查看紀錄",
                        color="#FFFFFF",
                        size="xl",
                        wrap=True,
                        align="center",
                    ),
                ]
            )
        else:
            for result in results:
                item = BoxComponent(
                    background_color="#EA8244",
                    layout='baseline',
                        contents=[
                            TextComponent(
                                type="text",
                                text=str(result.food_name),
                                color="#FFFFFF",
                                size="xs",
                                wrap=True,
                                align="center",
                            ),
                            TextComponent(
                                type="text",
                                text=str(result.food_quantity),
                                color="#FFFFFF",
                                size="xs",
                                wrap=True,
                                align="center",
                            ),
                            TextComponent(
                                type="text",
                                text=str(result.food_power),
                                color="#FFFFFF",
                                size="xs",
                                wrap=True,
                                align="center",
                            ),
                            TextComponent(
                                type="text",
                                text=str(result.food_protein),
                                color="#FFFFFF",
                                size="xs",
                                wrap=True,
                                align="center",
                            ),
                            TextComponent(
                                type="text",
                                text=str(result.food_carbohydrate),
                                color="#FFFFFF",
                                size="xs",
                                wrap=True,
                                align="center",
                            ),
                            TextComponent(
                                type="text",
                                text=str(result.food_fat),
                                color="#FFFFFF",
                                size="xs",
                                wrap=True,
                                align="center",
                            ),
                        ]
                    )
                item_list.append(item)

        return item_list

    temp1 = item_loop(length)
    i=0
    temp=[]
    while i < 11:
        if i<len(temp1):
            temp.append(temp1[i])
        else:
            temp.append(BoxComponent(background_color="#EA8244",layout='baseline',contents=[FillerComponent(flex=0)]))
        i+=1
    container = BubbleContainer(
        size='giga',
        body=BoxComponent(
            layout='vertical',
            background_color="#2e2e2e",
            size='sm',
            contents=[
                BoxComponent(
                    layout='vertical',
                    background_color="#2e2e2e",
                    contents=[
                        TextComponent(
                            text='今日飲食紀錄🍽',
                            weight="bold",
                            size="xl",
                            style="normal",
                            decoration="none",
                            gravity="center",
                            align="center",
                            color="#ffffff",
                            offset_bottom="1.25%",
                        ),
                        BoxComponent(
                            layout='baseline',
                            background_color="#EA8244",
                            contents=[
                                TextComponent(
                                    type="text",
                                    text="食物",
                                    size="sm",
                                    align="center",
                                    weight="bold",
                                ),
                                TextComponent(
                                    type='text',
                                    text="數量",
                                    wrap=True,
                                    size="sm",
                                    align="center",
                                    weight="bold",

                                ),
                                TextComponent(
                                    type='text',
                                    text="熱量",
                                    wrap=True,
                                    size="sm",
                                    align="center",
                                    weight="bold",
                                ),
                                TextComponent(
                                    type='text',
                                    text="蛋白質",
                                    wrap=True,
                                    size="sm",
                                    align="center",
                                    weight="bold",
                                ),
                                TextComponent(
                                    type='text',
                                    text="碳水",
                                    wrap=True,
                                    size="sm",
                                    align="center",
                                    weight="bold",
                                ),
                                TextComponent(
                                    type='text',
                                    text="脂肪",
                                    wrap=True,
                                    size="sm",
                                    align="center",
                                    weight="bold",
                                )
                            ]
                        ),
                        temp[0],
                        temp[1],
                        temp[2],
                        temp[3],
                        temp[4],
                        temp[5],
                        temp[6],
                        temp[7],
                        temp[8],
                        temp[9],
                        temp[10],
                    ]
                ),
            ],
        ),
        footer=BoxComponent(
            background_color="#2e2e2e",
            layout='vertical',
            spacing='sm',
            contents=[
                ButtonComponent(
                    style="primary",
                    height="sm",
                    action=URIAction(label="點我查看更多紀錄👀",
                                     uri=uri),
                    color="#EA8244",
                    gravity="center",
                ),
                SpacerComponent(size='sm'),
            ],
            flex=0,
        )
    )



    return FlexSendMessage(alt_text="今日飲食紀錄", contents=container)
Ejemplo n.º 5
0
def handle_message(event):
    if event.message.text == 'packages':
        gc = get_credential(json_keyfile)
        sheetkey = '15uhQm6tkd69dEthC-Vc9tb-Orsjnywlw85GOBsZgxmY'
        sh = gc.open_by_key(sheetkey)
        ws = sh.worksheet('packages')
        df = DataFrame(ws.get_all_records())
        bubbles = []
        for idx, row in df.iterrows():
            bubbles.append(
                BubbleContainer(hero=ImageComponent(
                    layout='vertical',
                    url="https://drive.google.com/uc?id={}".format(
                        row['cover']),
                    size='full',
                    aspect_mode='cover',
                    aspect_ratio='20:13',
                    action=MessageAction(
                        label='Test List',
                        text='Tests will be shown here in the future.')),
                                body=BoxComponent(
                                    layout='vertical',
                                    contents=[
                                        TextComponent(text=row['title'],
                                                      weight='bold',
                                                      size='xl',
                                                      wrap=True),
                                        TextComponent(text=row['description'],
                                                      wrap=True,
                                                      color='#cfcecc')
                                    ]),
                                footer=BoxComponent(
                                    layout='vertical',
                                    contents=[
                                        ButtonComponent(
                                            MessageAction(label='รายการตรวจ',
                                                          text=row['code']))
                                    ])))
        line_bot_mumthealth.reply_message(
            event.reply_token,
            FlexSendMessage(alt_text='Health Packages',
                            contents=CarouselContainer(contents=bubbles)))
    elif event.message.text == 'health-services':
        imageUrl = '1Z63x6wA08ATfWr1SgBCkMhiMbD3h2lhP'
        line_bot_mumthealth.reply_message(
            event.reply_token,
            ImagemapSendMessage(
                base_url='https://drive.google.com/uc?id={}&_ignored='.format(
                    imageUrl),
                alt_text='Health Services',
                base_size=BaseSize(width=1040, height=1040),
                actions=[
                    MessageImagemapAction(text='packages',
                                          area=ImagemapArea(x=122,
                                                            y=123,
                                                            width=381,
                                                            height=305)),
                    URIImagemapAction(
                        link_uri='https://liff.line.me/1655424321-ovYzaqOz',
                        area=ImagemapArea(x=124, y=430, width=377,
                                          height=301)),
                    MessageImagemapAction(text='Available soon..',
                                          area=ImagemapArea(x=126,
                                                            y=734,
                                                            width=374,
                                                            height=302)),
                    MessageImagemapAction(text='Available soon..',
                                          area=ImagemapArea(x=507,
                                                            y=125,
                                                            width=435,
                                                            height=301)),
                    MessageImagemapAction(text='Available soon..',
                                          area=ImagemapArea(x=508,
                                                            y=431,
                                                            width=434,
                                                            height=299)),
                ]))
    elif event.message.text.startswith('pkg'):
        gc = get_credential(json_keyfile)
        sheetkey = '15uhQm6tkd69dEthC-Vc9tb-Orsjnywlw85GOBsZgxmY'
        sh = gc.open_by_key(sheetkey)
        ws = sh.worksheet('tests')
        df = DataFrame(ws.get_all_records())
        bubbles = []
        total = 0
        for idx, row in df.iterrows():
            if row['package'] == event.message.text:
                total += row['price']
                bubbles.append(
                    BubbleContainer(body=BoxComponent(
                        layout='vertical',
                        contents=[
                            TextComponent(
                                text=row['test'],
                                weight='bold',
                                size='xl',
                                wrap=True,
                                align='center',
                            ),
                            TextComponent(text=row['description'],
                                          wrap=True,
                                          gravity='center'),
                            FillerComponent(flex=2),
                            TextComponent(text=u'{} บาท'.format(row['price']),
                                          wrap=True,
                                          weight='bold',
                                          size='xl',
                                          gravity='bottom',
                                          color='#4287f5',
                                          align='center')
                        ])))
        if len(bubbles) > 0:
            bubbles.append(
                BubbleContainer(
                    body=BoxComponent(layout='vertical',
                                      contents=[
                                          FillerComponent(flex=2, ),
                                          TextComponent(
                                              text='รวม {} บาท'.format(total),
                                              weight='bold',
                                              size='xl',
                                              gravity='center',
                                              align='center',
                                              color='#4287f5')
                                      ]),
                    footer=BoxComponent(
                        layout='vertical',
                        contents=[
                            ButtonComponent(action=URIAction(
                                label=u'นัดหมายเพื่อรับบริการ',
                                uri='https://liff.line.me/1655713713-L9yW3XWK')
                                            ),
                            ButtonComponent(action=MessageAction(
                                label=u'ข้อมูลเพิ่มเติม', text='Here you go!'))
                        ])))
            line_bot_mumthealth.reply_message(
                event.reply_token,
                FlexSendMessage(alt_text='Health Packages',
                                contents=CarouselContainer(contents=bubbles)))
    else:
        line_bot_mumthealth.reply_message(
            event.reply_token,
            TextSendMessage(text='Sorry, this feature will be available soon.'.
                            format(event.message.text)))
Ejemplo n.º 6
0
def handle_message(event):
    c = Calendar()
    if event.message.text == 'leaves':
        line_id = event.source.user_id
        user = StaffAccount.query.filter_by(line_id=line_id).first()
        if user:
            bubbles = []
            for quota in StaffLeaveQuota.query.filter_by(
                    employment_id=user.personal_info.employment.id):
                total_leaves = user.personal_info.get_total_leaves(
                    leave_quota_id=quota.id,
                    start_date=tz.localize(START_FISCAL_DATE),
                    end_date=tz.localize(END_FISCAL_DATE))
                bubbles.append(
                    BubbleContainer(
                        body=BoxComponent(
                            layout='vertical',
                            contents=[
                                TextComponent(text=u'{}'.format(
                                    quota.leave_type),
                                              weight='bold',
                                              size='xl',
                                              wrap=True),
                                FillerComponent(flex=2, ),
                                TextComponent(
                                    text=u'ใช้ไป {} วัน'.format(total_leaves),
                                    wrap=True,
                                    size='md')
                            ]),
                        footer=BoxComponent(
                            layout='vertical',
                            contents=[
                                ButtonComponent(action=URIAction(
                                    label=u'Make a request',
                                    uri='https://mumtmis.herokuapp.com')),
                            ])))
            line_bot_api.reply_message(
                event.reply_token,
                FlexSendMessage(alt_text='Leaves Info',
                                contents=CarouselContainer(contents=bubbles)))
    if event.message.text == 'events':
        today = datetime.today().date()
        this_week = []
        for week in c.monthdatescalendar(today.year, today.month):
            if today in week:
                this_week = [d for d in week]
                break
        events = requests.get(
            url_for('event.fetch_global_events', _external=True))
        bubbles = []
        for evt in events.json():
            start = dateutil.parser.parse(evt.get('start'))
            #TODO: recheck if .get file_id condition
            if evt.get('file_id'):
                event_id = evt.get('file_id')
            else:
                event_id = event_photo
            if start.date() in this_week:
                bubbles.append(
                    BubbleContainer(
                        hero=ImageComponent(
                            layout='vertical',
                            url="https://drive.google.com/uc?id={}".format(
                                event_id),
                            size='full',
                            aspect_mode='cover',
                            aspect_ratio='20:13',
                        ),
                        body=BoxComponent(
                            layout='vertical',
                            contents=[
                                TextComponent(text=u'{}'.format(
                                    evt.get('title')),
                                              weight='bold',
                                              size='xl',
                                              wrap=True),
                                TextComponent(
                                    text=u'วันที่ {} เวลา {} น.'.format(
                                        start.strftime(u'%d/%m/%Y'),
                                        start.strftime('%H:%M')),
                                    wrap=True),
                                TextComponent(text=u'สถานที่ {}'.format(
                                    evt.get('location') or u'ไม่ระบุ'),
                                              wrap=True),
                            ]),
                        footer=BoxComponent(
                            layout='vertical',
                            contents=[
                                ButtonComponent(
                                    action=URIAction(
                                        label=u'ลงทะเบียนกิจกรรมนี้ (Register)',
                                        uri=evt.get('registration')
                                        #uri='https://mt.mahidol.ac.th/calendar/events/'
                                    ), ),
                            ])))
        if bubbles:
            bubbles.append(
                BubbleContainer(
                    hero=ImageComponent(
                        layout='vertical',
                        url="https://drive.google.com/uc?id={}".format(
                            calendar_photo),
                        size='full',
                        aspect_mode='cover',
                        aspect_ratio='20:13',
                    ),
                    body=BoxComponent(
                        layout='vertical',
                        contents=[
                            ButtonComponent(action=URIAction(
                                label=u'ดูกิจกรรม (Event Detail)',
                                uri='https://mt.mahidol.ac.th/calendar/events/'
                            ), )
                        ])))
            line_bot_api.reply_message(
                event.reply_token,
                FlexSendMessage(alt_text='Events Info',
                                contents=CarouselContainer(contents=bubbles)))
        else:
            line_bot_api.reply_message(
                event.reply_token,
                FlexSendMessage(
                    alt_text='Events Info',
                    contents=CarouselContainer(contents=[
                        BubbleContainer(
                            body=BoxComponent(
                                layout='vertical',
                                contents=[
                                    TextComponent(
                                        text=u'ไม่มีกิจกรรมในสัปดาห์นี้',
                                        weight='bold',
                                        size='xl',
                                        wrap=True)
                                ]),
                            footer=BoxComponent(
                                layout='vertical',
                                contents=[
                                    ButtonComponent(action=URIAction(
                                        label=u'ดูปฏิทิน (Calendar)',
                                        uri=
                                        'https://mt.mahidol.ac.th/calendar/events/'
                                    )),
                                ]))
                    ])))