Commit b333b09f authored by Jalin's avatar Jalin

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

parent c8988cd2
...@@ -105,6 +105,10 @@ def get_file_total_line_num(file, encoding='utf-8'): ...@@ -105,6 +105,10 @@ def get_file_total_line_num(file, encoding='utf-8'):
return len(f.readlines()) 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): def str_to_time(str):
return datetime.datetime.strptime(str, '%Y-%m-%d %H:%M:%S.%f') return datetime.datetime.strptime(str, '%Y-%m-%d %H:%M:%S.%f')
......
...@@ -41,6 +41,7 @@ class Query: ...@@ -41,6 +41,7 @@ class Query:
if auto: if auto:
QueryLog.add_quick_log(QueryLog.MESSAGE_JOBS_DID_CHANGED).flush() QueryLog.add_quick_log(QueryLog.MESSAGE_JOBS_DID_CHANGED).flush()
self.refresh_jobs() self.refresh_jobs()
jobs_do(self.jobs, 'check_passengers')
@classmethod @classmethod
def run(cls): def run(cls):
......
...@@ -5,7 +5,7 @@ from flask.json import jsonify ...@@ -5,7 +5,7 @@ from flask.json import jsonify
from flask_jwt_extended import (jwt_required) from flask_jwt_extended import (jwt_required)
from py12306.config import Config 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.log.common_log import CommonLog
from py12306.query.query import Query from py12306.query.query import Query
from py12306.user.user import User from py12306.user.user import User
...@@ -29,17 +29,19 @@ def log_output(): ...@@ -29,17 +29,19 @@ def log_output():
if last_line == -1: if last_line == -1:
total_line = get_file_total_line_num(file) total_line = get_file_total_line_num(file)
last_line = total_line - max_old if total_line > max_old else 0 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: else:
ranges = range(limit) ranges = range(last_line, last_line + limit)
if Config().OUT_PUT_LOG_TO_FILE_ENABLED: if Config().OUT_PUT_LOG_TO_FILE_ENABLED:
# with open(Config().OUT_PUT_LOG_TO_FILE_PATH, 'r', encoding='utf-8') as f: with open(Config().OUT_PUT_LOG_TO_FILE_PATH, 'r', encoding='utf-8') as f:
# res = f.readlines()[last_line:limit] res = pick_file_lines(f, ranges)
linecache.updatecache(file)
for i in ranges: # linecache.updatecache(file) # 使用 linecache windows 平台会出来编码问题 暂时弃用
tmp = linecache.getline(file, last_line + i) # for i in ranges:
if tmp != '': res.append(tmp) # tmp = linecache.getline(file, last_line + i)
# if tmp != '': res.append(tmp)
last_line += len(res) last_line += len(res)
else: else:
res = CommonLog.MESSAGE_OUTPUT_TO_FILE_IS_UN_ENABLE res = CommonLog.MESSAGE_OUTPUT_TO_FILE_IS_UN_ENABLE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment