废话不多说,先抽一卦。(仅供娱乐)

随机一卦http://182.254.246.137/life
运气一卦http://182.254.246.137/better

运行效果
在这里插入图片描述

手机浏览器访问
在这里插入图片描述

源码:

# -*- coding: utf-8 -*-
import random
import xlrd
from sanic import Sanic
from sanic import response

app = Sanic('myapp')

filename = "life64.xls"
data = xlrd.open_workbook(filename)
table = data.sheets()[0]


@app.get('/life')
def life(request):

    number = random.randint(0, 63)
    luck_type = table.row_values(number)[2][:-1]

    if luck_type in ["上上"]:
        word = "恭喜您!您抽到上上签!"
    elif luck_type in ["下下"]:
        word = "很遗憾!您抽到下下签!"
    else:
        word = "您抽中的是:{}签!".format(luck_type)

    message = {
        "前言": word,
        "第几卦": table.row_values(number)[0],
        "卦名": table.row_values(number)[1],
        "解卦": table.row_values(number)[3]
    }
    html_message = f"""
    <body>
    <h4>{word}</h4>
    <p>第几卦:{table.row_values(number)[0]}</p>
    <p>卦名:{table.row_values(number)[1]}</p>
    <p>解卦:{table.row_values(number)[3][3:50]}</p>
    <p>      {table.row_values(number)[3][50:]}</p>
    <br>
    <p style="color: red">温馨提示:随机抽取,权当笑尔。</p>
	</body>
    """
    return response.html(html_message)


@app.get('/better')
def better(request):
    lucky_number = [0, 1, 7, 13, 20, 26, 41, 42, 45, 47, 48, 52, 54, 57, 59]

    number = random.choice(lucky_number)
    luck_type = table.row_values(number)[2][:-1]

    if luck_type in ["上上"]:
        word = "恭喜您!您抽到上上签!"
    elif luck_type in ["下下"]:
        word = "很遗憾!您抽到下下签!"
    else:
        word = "您抽中的是:{}签!".format(luck_type)

    message = {
        "前言": word,
        "第几卦": table.row_values(number)[0],
        "卦名": table.row_values(number)[1],
        "解卦": table.row_values(number)[3]
    }
    html_message = f"""
        <body>
        <h4>{word}</h4>
        <p>第几卦:{table.row_values(number)[0]}</p>
        <p>卦名:{table.row_values(number)[1]}</p>
        <p>解卦:{table.row_values(number)[3][3:50]}</p>
        <p>      {table.row_values(number)[3][50:]}</p>
        <br>
        <p style="color: red">温馨提示:随机抽取,权当笑尔。</p>
    </body>
        """
    return response.html(html_message)


if __name__ == "__main__":
    app.run(host="127.0.0.1", port=80, auto_reload=True

微信公众号:玩转测试开发
欢迎关注,共同进步,谢谢!

在这里插入图片描述

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐