修复 bug #16,增加任务更新后重新检测乘客

This commit is contained in:
Jalin
2019-01-14 18:18:26 +08:00
parent 550c87d77a
commit d0b61852d3
3 changed files with 16 additions and 9 deletions

View File

@@ -105,6 +105,10 @@ def get_file_total_line_num(file, encoding='utf-8'):
return len(f.readlines())
def pick_file_lines(file, lines):
return [x for i, x in enumerate(file) if i in lines]
def str_to_time(str):
return datetime.datetime.strptime(str, '%Y-%m-%d %H:%M:%S.%f')

View File

@@ -41,6 +41,7 @@ class Query:
if auto:
QueryLog.add_quick_log(QueryLog.MESSAGE_JOBS_DID_CHANGED).flush()
self.refresh_jobs()
jobs_do(self.jobs, 'check_passengers')
@classmethod
def run(cls):

View File

@@ -5,7 +5,7 @@ from flask.json import jsonify
from flask_jwt_extended import (jwt_required)
from py12306.config import Config
from py12306.helpers.func import get_file_total_line_num
from py12306.helpers.func import get_file_total_line_num, pick_file_lines
from py12306.log.common_log import CommonLog
from py12306.query.query import Query
from py12306.user.user import User
@@ -29,17 +29,19 @@ def log_output():
if last_line == -1:
total_line = get_file_total_line_num(file)
last_line = total_line - max_old if total_line > max_old else 0
ranges = range(max_old + limit)
ranges = range(last_line, last_line + max_old + limit)
# limit = max_old + limit
else:
ranges = range(limit)
ranges = range(last_line, last_line + limit)
if Config().OUT_PUT_LOG_TO_FILE_ENABLED:
# with open(Config().OUT_PUT_LOG_TO_FILE_PATH, 'r', encoding='utf-8') as f:
# res = f.readlines()[last_line:limit]
linecache.updatecache(file)
for i in ranges:
tmp = linecache.getline(file, last_line + i)
if tmp != '': res.append(tmp)
with open(Config().OUT_PUT_LOG_TO_FILE_PATH, 'r', encoding='utf-8') as f:
res = pick_file_lines(f, ranges)
# linecache.updatecache(file) # 使用 linecache windows 平台会出来编码问题 暂时弃用
# for i in ranges:
# tmp = linecache.getline(file, last_line + i)
# if tmp != '': res.append(tmp)
last_line += len(res)
else:
res = CommonLog.MESSAGE_OUTPUT_TO_FILE_IS_UN_ENABLE