Skip to content

Commit 938a4b3

Browse files
committed
chore: update year checker
1 parent e09e809 commit 938a4b3

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/tju_expense/__main__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import sys
99
import argparse
10+
import re
1011
import pandas as pd
1112
from pathlib import Path
1213
from 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():
5657
def 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} 年")

src/tju_expense/fetch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
BASE_URL = "http://59.67.37.10:8180"
1414
URLS = {
15+
"repo": "https://github.com/superpung/tju-expense",
1516
"finance": "https://finance.tju.edu.cn/",
1617
"login": f"{BASE_URL}/epay/person/index",
1718
"user_info": f"{BASE_URL}/epay/personaccount/index",

0 commit comments

Comments
 (0)