美文网首页
在安卓上部署flask小应用

在安卓上部署flask小应用

作者: JM68 | 来源:发表于2019-03-13 21:41 被阅读0次

QPythonL

在应用商城发现一个有趣的安卓python终端QpythonL并且包含包安装工具, 不过不知道安装源是否是国外,所以可能下载包需要一点时间,打开app界面,选择QPYPI安装flaskpip install flask

Screenshot_2019-03-13-21-10-21-726_com.hipipal.qp.png
Screenshot_2019-03-13-21-09-59-970_com.hipipal.qp.png Screenshot_2019-03-13-21-10-08-475_com.hipipal.qp.png

用flask写一个上班打卡app

在电脑上写好代码传手机上的, 触屏撸码有点难受的
app.py

from flask import Flask, request, render_template
from datetime import datetime
import json

app = Flask(__name__)

# 计算工时
def count_time():
    # 需要写文件的绝对路径
    wait_t = json.load(open("/storage/emulated/0/work_time/work_time.json"))
    wait = []
    for i in wait_t:
        for j in wait_t[i]:
            start_work = wait_t[i][j][0]
          
            after_work = wait_t[i][j][-1]
           # 8.30到9.30弹性打卡 12.到13.30午休 6.到6.30晚饭时间
           # 平均工时不得低于8小时 
            if start_work == after_work:
                every_day = -8
      
            elif 18 < after_work < 18.5:
                every_day = 18 - start_work - 9.5
            else:
                every_day = after_work - start_work - 10
            wait.append(every_day)
    print wait
    resp = 0
    for every_day in wait:
        resp += every_day
    return round(resp, 2)

@app.route('/', methods=["POST", "GET"])
def index():
    now = datetime.now()
    date = dict()
    date["hour"] = now.hour
    date["min"] = now.minute
    date["day"] = now.day
    date["mon"] = now.month
    if request.method == "GET":
        resp = count_time()
        return render_template("index.html", date=date, resp=resp)
    if request.method == "POST":
        work_time = request.form["work_time"]
        my_work_time = json.load(open("/storage/emulated/0/work_time/work_time.json"))
        hour = work_time.split(":")[0].strip()
        minute = work_time.split(":")[-1].strip()

        update_time = round(int(hour) + float(minute) / 60, 2)
        my_work_time[str(now.month)] = {} if str(now.month) not in my_work_time else my_work_time[str(now.month)]
        my_work_time[str(now.month)][str(now.day)] = [] if str(now.day) not in my_work_time[str(now.month)] else \
            my_work_time[str(now.month)][str(now.day)]
        my_work_time[str(now.month)][str(now.day)].append(update_time)
        json.dump(my_work_time, open("/storage/emulated/0/work_time/work_time.json", "w"))
        resp = count_time()
        return render_template("index.html", date=date, resp=resp)


if __name__ == '__main__':
    app.run(port=10058, debug=True)

templates/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WORK TIME</title>
    <style>
        body {
            background-color: black;
            text-align: center;
        }
        #c_time{
            color: white;
            font-size: 40px;
        }
        #input-circle{
            border-radius: 25px;
            padding: 20px;
            width: 46%;
            height: 2%;
            text-align: center;
            position: absolute;
            top:20%;
            left: 25%;
        }

        #btn-success {
            border-radius: 50%;
            padding: 20px;
            width: 50%;
            height: 30%;
            text-align: center;
            position: absolute;
            top: 30%;
            left: 25%;
            font-size: 50px;
            color: black;

        }
    </style>
</head>
<body>
<form action="/">
        <!-- Text input-->
        <input type="text" value="{{ date.hour }} : {{ date.min }}" id="input-circle" name="work_time">
        <p id="c_time">工时计算:{{ resp }}</p>
        <!-- Button -->
        <button id="btn-success" formmethod="post" formaction="/">打卡</button>
</form>


</body>
</html>

work_time.json 初始为空

{}

样式有点丑

工时计算还可以设计更完善一点 存一个桌面书签方便打开


Screenshot_2019-03-13-21-37-13-686_com.miui.home.png Screenshot_2019-03-13-21-37-23-764_com.tencent.mt.png

相关文章

网友评论

      本文标题:在安卓上部署flask小应用

      本文链接:https://www.haomeiwen.com/subject/mzrxmqtx.html