iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 25
1

今天我們要完成的是機房服務列表,
一個機房可能有其他相關的服務,
我們要做一個簡單就能串連到他們的功能,
首先在message.py新增上,

class roomlable():
    def returna(self):
        urldata = []
        namedata = []
        accpasdata= []
        statusdata = []
        serviceList = ""
        for serviceList in serviceListdata.find():
            name = serviceList["name"]
            url = serviceList["url"]
            accpas = serviceList["notice"]
            status = serviceList["enabled"]
            namedata.append(name)
            urldata.append(url)
            accpasdata.append(accpas)
            statusdata.append(status)

        flex_message = FlexSendMessage(
            alt_text='hello',
            contents={
            "type": "bubble",
            "size": "mega",
            "header": {
                "type": "box",
                "layout": "vertical",
                "contents": [
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "機房服務列表",
                        "color": "#ffffff",
                        "size": "xl",
                        "flex": 4,
                        "weight": "regular",
                        "margin": "xs"
                    }
                    ]
                }
                ],
                "paddingAll": "20px",
                "backgroundColor": "#0367D3",
                "spacing": "md",
                "height": "80px",
                "paddingTop": "22px"
            },
            "body": {
                "type": "box",
                "layout": "vertical",
                "contents": [
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[0]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[0])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+ str(statusdata[0])
                    },
                    {
                        "type": "text",
                        "text": "備註:"+ str(accpasdata[0])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "ccc",
                                "uri": "cccc"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[1]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[1])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:" + str(statusdata[1])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "cccc",
                                "uri": "cccc"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[2]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[2])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[2])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "cccc",
                                "uri": "cccc"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[3]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[3])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[3])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "cccc",
                                "uri": "cccc"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[4]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[4])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[4])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "cccc",
                                "uri": "ccccc"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[5]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[5])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[5])
                    },
                    {
                        "type": "text",
                        "text": "備註:"+ str(accpasdata[5])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "cccc",
                                "uri": "cccc"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[6]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[6])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[6])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "cccc",
                                "uri": "ccccc"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[7]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[7])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[7])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "ggggg",
                                "uri": "ggggg"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[8]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[8])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[8])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "CCC",
                                "uri": "CCCC"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[9]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[9])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[9])
                    },
                    {
                        "type": "text",
                        "text": "備註:"+ str(accpasdata[9])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "CCC",
                                "uri": "CCCC"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                    {
                        "type": "text",
                        "text": "服務名稱:"+ str(namedata[10]),
                        "size": "lg",
                        "color": "#0367D3"
                    },
                    {
                        "type": "text",
                        "text": "服務網址:"+ str(urldata[10])
                    },
                    {
                        "type": "text",
                        "text": "服務啟用狀態:"+str(statusdata[10])
                    },
                    {
                        "type": "box",
                        "layout": "vertical",
                        "contents": [
                        {
                            "type": "box",
                            "layout": "vertical",
                            "contents": [
                            {
                                "type": "button",
                                "action": {
                                "type": "uri",
                                "label": "CCCC",
                                "uri": "CCCC"
                                },
                                "color": "#FFFFFF"
                            }
                            ],
                            "backgroundColor": "#FFA500"
                        }
                        ]
                    }
                    ]
                }
                        }
                        ]
                    }
                    ]
                }
                ]
            }
            }
        )
        return flex_message

這邊我有將服務名稱(lable)鏈結網址(uri)改掉,
如果要使用就是在這邊對印對自己想要的即可,
然後在views.py新增上,

if event.message.text == "機房服務列表":

                    line_bot_api.reply_message(  # 回復「機房服務列表」按鈕輪播訊息
                        event.reply_token,
                        roomlable().returna()
                    )

就完成啦!
下一篇將會對於這個小linebot做一個總結。


今天是 陳鈺羲 的 我們不需要我們 網址如下~~~

https://www.youtube.com/watch?v=FTGsdD8k3NY&list=PLZ_d6NX2sE80xcb4RjHSCBt3E1nTclmC4&index=15&ab_channel=%E9%99%B3%E9%88%BA%E7%BE%B2



上一篇
Day24 機房好狗走起(4)
下一篇
Day26 機房好狗完結篇(6)
系列文
狗狗 Line Bot 以python及Django建構30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言