77import os
88import sys
99import argparse
10+ import re
1011import pandas as pd
1112from pathlib import Path
1213from dotenv import load_dotenv
@@ -33,9 +34,9 @@ def get_args():
3334 args .cookie = os .getenv ('COOKIE' )
3435
3536 if not args .cookie :
36- console .log (f "未定义 Cookie, 请根据以下步骤获取 Cookie:" )
37+ console .log ("未定义 Cookie, 请根据以下步骤获取 Cookie:" )
3738 console .print (f"1. 使用浏览器访问天津大学财务处官网 { URLS ['finance' ]} , 点击\" 一卡通服务平台\" (或直接访问校园卡网站 { URLS ['login' ]} ) 并登录" )
38- console .print (f "2. F12 打开 开发者工具 - Application - Storage - Cookies, 拷贝其中 JSESSIONID 的 Value" )
39+ console .print ("2. F12 打开 开发者工具 - Application - Storage - Cookies, 拷贝其中 JSESSIONID 的 Value" )
3940 args .cookie = Prompt .ask ("3. 粘贴 Cookie 至此处" )
4041 if not args .cookie :
4142 error_console .log ("[red]Cookie 不能为空" )
@@ -56,7 +57,7 @@ def get_font_path():
5657def main ():
5758 """Main program flow"""
5859 console .rule (f"[bold]TJU Expense[/bold] [dim]v{ version ('tju-expense' )} [/dim]" )
59- console .rule (f"[italic]https://github.com/superpung/tju-expense " )
60+ console .rule (f"[italic]{ URLS [ 'repo' ] } " )
6061
6162 # 设置字体
6263 font_path = get_font_path ()
@@ -92,10 +93,13 @@ def main():
9293 default = default_year ,
9394 show_default = False
9495 )
95- if input_year .isdigit () and 2000 <= int (input_year ) <= current_date .year :
96- year = input_year
96+
97+ year_match = re .search (r'20\d{2}' , input_year )
98+ if year_match :
99+ year = year_match .group ()
97100 else :
98101 year = default_year
102+ error_console .log (f"[red]无法解析输入的年份: { input_year } , 本次将统计默认年份数据, 请稍后重试并输入 4 位数字的年份" )
99103
100104 start , end = f"{ year } -01-01" , f"{ year } -12-31"
101105 console .rule (f"[bold]{ year } 年" )
0 commit comments