QPythonL
在應(yīng)用商城發(fā)現(xiàn)一個(gè)有趣的安卓python終端QpythonL并且包含包安裝工具, 不過(guò)不知道安裝源是否是國(guó)外,所以可能下載包需要一點(diǎn)時(shí)間,打開(kāi)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寫一個(gè)上班打卡app
在電腦上寫好代碼傳手機(jī)上的, 觸屏擼碼有點(diǎn)難受的
app.py
from flask import Flask, request, render_template
from datetime import datetime
import json
app = Flask(__name__)
# 計(jì)算工時(shí)
def count_time():
# 需要寫文件的絕對(duì)路徑
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晚飯時(shí)間
# 平均工時(shí)不得低于8小時(shí)
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">工時(shí)計(jì)算:{{ resp }}</p>
<!-- Button -->
<button id="btn-success" formmethod="post" formaction="/">打卡</button>
</form>
</body>
</html>
work_time.json
初始為空
{}
樣式有點(diǎn)丑
工時(shí)計(jì)算還可以設(shè)計(jì)更完善一點(diǎn) 存一個(gè)桌面書簽方便打開(kāi)
Screenshot_2019-03-13-21-37-13-686_com.miui.home.png
Screenshot_2019-03-13-21-37-23-764_com.tencent.mt.png