Skip to content

Commit 865dd1c

Browse files
committed
添加日期自动转换和一个隐藏配置date_auto_zfill控制是否自动补0
1 parent e0e89fe commit 865dd1c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

QBRssManager.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import re
34
import subprocess
45
import sys
56
import time
@@ -75,6 +76,8 @@ def save_config(update_data=True):
7576
config['center_columns'] = [0, 3, 4]
7677
if 'close_to_tray' not in config:
7778
config['close_to_tray'] = 1
79+
if 'date_auto_zfill' not in config:
80+
config['date_auto_zfill'] = 0
7881
except:
7982

8083
# 默认配置
@@ -96,6 +99,7 @@ def save_config(update_data=True):
9699
config['data_list'] = data_list
97100
config['auto_save'] = auto_save
98101
config['max_row_size'] = max_row_size
102+
config['date_auto_zfill'] = 0
99103

100104
with open('config.json', 'w', encoding='utf-8') as f:
101105
f.write(json.dumps(config, ensure_ascii=False, indent=4))
@@ -112,6 +116,22 @@ def format_path(s):
112116
return s.replace('\\', '/').replace('//', '/')
113117

114118

119+
def try_convert_time(s):
120+
"""
121+
简单粗暴的字符串转换年月
122+
比如 2021.11 2021-11 2021/11 转换成2021年11月
123+
"""
124+
res = re.match(r'^(\d{4})[\.\-\_\\/](\d{1,2})$', s)
125+
if res:
126+
year = str(res[1])
127+
month = str(res[2])
128+
129+
if config['date_auto_zfill'] == 1:
130+
month = month.zfill(2)
131+
s = f'{year}{month}月'
132+
return s
133+
134+
115135
qb_executable_name = format_path(config['qb_executable']).rsplit('/', 1)[-1]
116136

117137

@@ -352,6 +372,12 @@ def on_cell_changed(self):
352372
c = self.tableWidget.currentColumn()
353373
text = self.tableWidget.currentItem().text()
354374
print(r, c, text)
375+
376+
# 第一列时间进行特殊转换处理
377+
if c == 0:
378+
text = try_convert_time(text)
379+
self.tableWidget.currentItem().setText(text)
380+
355381
# 修改数据
356382
data_list[r][c] = text
357383
print('on_cell_changed 结果', data_list)

0 commit comments

Comments
 (0)