Skip to content

Commit

Permalink
optimised encoding issues and added refresh function
Browse files Browse the repository at this point in the history
  • Loading branch information
CitingNutria authored Mar 17, 2022
1 parent bc61625 commit 9133de0
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions kedama_bill_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def create_folder(folder_name):
os.makedirs(user_documents + '/' + folder_name)
return user_documents + '/' + folder_name




cache_path = create_folder('Kedama Logs Reader')

if not os.path.exists(cache_path+ '\\logs.txt'):
Expand All @@ -24,47 +27,46 @@ def create_folder(folder_name):
logs_path = f.read()


while True:
# create a logs list
logs_list = []
gz_list = []
# create a list of files with .gz in the logs folder
for file in os.listdir(logs_path):
if file.endswith(".gz"):
try:
with gzip.open(logs_path + "\\" + file, 'rt', encoding='utf-8') as f:
file_content = f.read()
for line in file_content.splitlines():
if '您收到了' in line:
info = file[0:-9] + ' ' + line[0:11] + line[39:]
logs_list.append(info)
except:
with gzip.open(logs_path + "\\" + file, 'rt', encoding='gbk') as f:
file_content = f.read()
for line in file_content.splitlines():
if '您收到了' in line:
info = file[0:-9] + ' ' + line[0:11] + line[39:]
logs_list.append(info)

latest_log = logs_path + "\\latest.log"

# get now date
now = datetime.datetime.now()

# read the latest log file
with open(latest_log, 'r') as f:
for line in f:
if "您收到了" in line:
logs_list.append(str(now)[0:10] + ' ' + line[0:11] + line[39:])

# print the logs list line by line
for line in logs_list:
print(line)

# create a logs list
logs_list = []
gz_list = []
# create a list of files with .gz in the logs folder
for file in os.listdir(logs_path):
if file.endswith(".gz"):
with gzip.open(logs_path+"\\"+file, 'rt') as f:
file_content = f.read()
for line in file_content.splitlines():
if '您收到了' in line:
info = file[0:-9]+' '+line[0:11] + line[39:]
logs_list.append(info)






latest_log = logs_path + "\\latest.log"

# get now date
now = datetime.datetime.now()


# read the latest log file
with open(latest_log, 'r') as f:
for line in f:
if "您收到了" in line:
logs_list.append(str(now)[0:10]+' '+line[0:11] + line[39:])

exit = input('按回车刷新')

# print the logs list line by line
for line in logs_list:
print(line)


exit = input('按任意键退出')


0 comments on commit 9133de0

Please sign in to comment.