Skip to content

Commit

Permalink
20200531更新
Browse files Browse the repository at this point in the history
  • Loading branch information
AragonSnow committed May 30, 2020
1 parent e0bbc77 commit 7274821
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 71 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ docker地址:[https://hub.docker.com/r/asdaragon/qiandao](https://hub.docker.c

docker部署命令:``` docker run -d --name qiandao -p 12345:80 -v $(pwd)/qiandao/config:/usr/src/app/config asdaragon/qiandao ```

## 2020.5.31 更新
1. 修复定时 ‘day out of month’ 的BUG
2. 取消定时界面的今日运行选项,自动判断当前时间是今天还是第二天

## 2020.5.30 更新
1. 修改 任务失败时 推送的消息内容为 任务日志;
2. 因浏览器支持不好,取消 2020.5.18更新的 ‘模板上传指定格式为.har’;
Expand Down
20 changes: 4 additions & 16 deletions logdaily.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import json
import time
import datetime
import pytz

import send2phone
from web.handlers.task import calNextTimestamp

def tostr(s):
if isinstance(s, bytearray):
Expand Down Expand Up @@ -68,21 +68,9 @@ def logpusher(self, path=config.sqlite3.path):
wxp_temp = user['wxpusher'].split(";")
s = send2phone.send2phone(wxpusher_token=wxp_temp[0], wxpusher_uid=wxp_temp[1])
s.send2wxpusher(temp)

tz = pytz.timezone('Asia/Shanghai')
now = datetime.datetime.now()
now = datetime.datetime(year=now.year, month=now.month, day=now.day, hour=now.hour, minute=now.minute, tzinfo=tz)
temp = logtime['time'].split(":")
ehour = int(temp[0])
emin = int(temp[1])
esecond = int(temp[2])
pre = datetime.datetime(year=now.year, month=now.month, day=now.day, hour=ehour, minute=emin,second=esecond,tzinfo=tz)
now_ts = int(time.time())
next = int(time.mktime(pre.timetuple()) + pre.microsecond/1e6)
if (now_ts > next):
pre = datetime.datetime(year=now.year, month=now.month, day=now.day+1, hour=ehour, minute=emin,second=esecond,tzinfo=tz)
next = int(time.mktime(pre.timetuple()) + pre.microsecond/1e6)
logtime['ts'] = next

next_ts = calNextTimestamp(logtime['time'])
logtime['ts'] = next_ts

self.db.user.mod(user['id'], logtime=json.dumps(logtime))
except Exception as e:
Expand Down
44 changes: 14 additions & 30 deletions web/handlers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,19 @@

from base import *

def calNextTimestamp(etime, todayflg):
def calNextTimestamp(etime):
tz = pytz.timezone('Asia/Shanghai')
now = datetime.datetime.now()
now = datetime.datetime(year=now.year,
month=now.month,
day=now.day,
hour=now.hour,
minute=now.minute,
tzinfo=tz)
now_ts = int(time.time())
zero = datetime.datetime(year=now.year, month=now.month, day=now.day, hour=0, minute=0, second=0, tzinfo=tz)
zero_ts = int(time.mktime(zero.timetuple()) + zero.microsecond/1e6)
temp = etime.split(":")
if (todayflg):
eday = now.day
else:
eday = now.day+1
ehour = int(temp[0])
emin = int(temp[1])
esecond = int(temp[2])
pre = datetime.datetime(year=now.year,
month=now.month,
day=eday,
hour=ehour,
minute=emin,
second=esecond,
tzinfo=tz)
next = int(time.mktime(pre.timetuple()) + pre.microsecond/1e6)
return next
e_ts = int(temp[0]) * 3600 + int(temp[1]) * 60 + int(temp[2])
next_ts = zero_ts + e_ts
if (now_ts > next_ts):
next_ts = next_ts + (24 * 60 * 60)

return next_ts

class TaskNewHandler(BaseHandler):
def get(self):
Expand Down Expand Up @@ -169,7 +156,7 @@ def post(self, taskid):

self.db.tasklog.add(task['id'], success=True, msg=new_env['variables'].get('__log__'))
if (task["ontimeflg"] == 1):
nextTime = calNextTimestamp(task["ontime"], todayflg=False)
nextTime = calNextTimestamp(task["ontime"])
else:
nextTime = time.time() + (tpl['interval'] if tpl['interval'] else 24 * 60 * 60)

Expand Down Expand Up @@ -230,10 +217,10 @@ def get(self, taskid):

variables = json.loads(tpl['variables'])
todayflg = True if task['ontimeflg'] == 1 else False
now = datetime.datetime.now().strftime( '%H:%M:%S')
# now = datetime.datetime.now().strftime( '%H:%M:%S')
onetime = task['ontime']

self.render('task_setTime.html', tpls=[tpl, ], tplid=tpl['id'], tpl=tpl, task=task, ontimeflg=todayflg, mintime=now, onetime=onetime)
self.render('task_setTime.html', tpls=[tpl, ], tplid=tpl['id'], tpl=tpl, task=task, ontimeflg=todayflg, onetime=onetime)

@tornado.web.authenticated
def post(self, taskid):
Expand All @@ -253,10 +240,7 @@ def post(self, taskid):

if ('flg' in self.request.body_arguments):
OntimeFlg = 1
if ('todayflg' in self.request.body_arguments):
next = calNextTimestamp(ontime, todayflg=True)
else:
next = calNextTimestamp(ontime, todayflg=False)
next = calNextTimestamp(ontime)
else :
OntimeFlg = 0
next = time.time() + (tpl['interval'] if tpl['interval'] else 24 * 60 * 60)
Expand Down
18 changes: 3 additions & 15 deletions web/handlers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from base import *

import send2phone
import pytz
from web.handlers.task import calNextTimestamp

class UserRegPush(BaseHandler):
@tornado.web.authenticated
Expand Down Expand Up @@ -142,20 +142,8 @@ def post(self, userid):
logtime['schanEn'] = True if ('schanlogsw' in env) else False
logtime['WXPEn'] = True if ('wxpusherlogsw' in env) else False

tz = pytz.timezone('Asia/Shanghai')
now = datetime.datetime.now()
now = datetime.datetime(year=now.year, month=now.month, day=now.day, hour=now.hour, minute=now.minute, tzinfo=tz)
temp = logtime['time'].split(":")
ehour = int(temp[0])
emin = int(temp[1])
esecond = int(temp[2])
pre = datetime.datetime(year=now.year, month=now.month, day=now.day, hour=ehour, minute=emin,second=esecond,tzinfo=tz)
now_ts = int(time.time())
next = int(time.mktime(pre.timetuple()) + pre.microsecond/1e6)
if (now_ts > next):
pre = datetime.datetime(year=now.year, month=now.month, day=now.day+1, hour=ehour, minute=emin,second=esecond,tzinfo=tz)
next = int(time.mktime(pre.timetuple()) + pre.microsecond/1e6)
logtime['ts'] = next
next_ts = calNextTimestamp(logtime['time'])
logtime['ts'] = next_ts

for e in env:
temp = re.findall(r"(.+?)logen", e)
Expand Down
12 changes: 3 additions & 9 deletions web/tpl/task_setTime.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2 class="text-center">私有签到框架<sup>alpha</sup></h2>
</select>
</div>

<input type="time" id="timevalue" value="00:00:00" name='timevalue', step="1" min="{{ mintime }}"/>
<input type="time" id="timevalue" value="00:00:00" name='timevalue', step="1" />

{% if current_user %}
<div class="form-group">
Expand All @@ -37,28 +37,22 @@ <h2 class="text-center">私有签到框架<sup>alpha</sup></h2>
<input type="checkbox" id="flg" name="flg" {% if ontimeflg %} checked="" {% endif %}> 强制每天定时
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="todayflg" name="todayflg" checked="checked" onchange="checkboxOnclick(this)"> 今天运行
</label>
</div>

<div class="text-right">
{% if current_user %}
<button id="send" data-method="POST" href="/task/{{ task.id }}/settime" class="btn btn-primary">提交</button>
{% endif %}
</div>


<script>
<!-- <script>
function checkboxOnclick(checkbox){
if (checkbox.checked == true){
document.getElementById("timevalue").min="{{ mintime }}";
}else{
document.getElementById("timevalue").min="00:00:00";
}
}
</script>
</script> -->

{{ utils.task_new_scripts() }}
{{ utils.submit_loading() }}
Expand Down
2 changes: 1 addition & 1 deletion worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def do(self, task):

# todo next not mid night
if (ontime['ontimeflg'] == 1):
next = calNextTimestamp(ontime['ontime'], todayflg=False)
next = calNextTimestamp(ontime['ontime'])
else:
next = time.time() + max((tpl['interval'] if tpl['interval'] else 24 * 60 * 60), 1*60)
if tpl['interval'] is None:
Expand Down

0 comments on commit 7274821

Please sign in to comment.