Skip to content

Commit

Permalink
fix terrible bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinTerry committed Jul 25, 2023
1 parent bbe21f7 commit 07e7d2f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__
dist
build
hust_login.egg-info
secret.txt
2 changes: 1 addition & 1 deletion hust_login/_HustPass.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def QueryFreeRoom(self, QueryData:str) -> dict:
self.CheckLoged()
return GetFreeRoom(self.Session, QueryData)

def QueryEcardBills(self, QueryData:str) -> list:
def QueryEcardBills(self, QueryData:str|list[str]|tuple[str,str]) -> list:
'''
PARAMETERS:\n
session -- should be already logged in\n
Expand Down
12 changes: 6 additions & 6 deletions hust_login/ecard_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_yyyy_mm_between_dates(date_range:tuple) -> list:
# Start iterating from the start_date to end_date (inclusive)
current_date = start_date
while current_date <= end_date:
yyyy_mm_dates.append(current_date.strftime("%Y-%m"))
yyyy_mm_dates.append(current_date.replace(day=1).strftime("%Y-%m-%d"))
current_date += timedelta(days=32) # Increment by 32 days to move to the next month

# Adjust the current_date to the first day of the next month
Expand Down Expand Up @@ -78,7 +78,7 @@ def _GetMonth(session:requests.Session, account:str, _QueryMonth:str) -> list:
current_page = next_page_obt
url = '{}?account={}&curpage={}&dateStatus={}&typeStatus=1'.format(url_base,account,current_page,_QueryMonth)
resp = session.get(url).text
print(resp.strip().strip('callJson(').strip(')'))
# print(resp.strip().strip('callJson(').strip(')'))
raw = json.loads(resp.strip().strip('callJson(').strip(')'))
next_page_obt = str(raw['nextpage'])
entrys = raw['total']
Expand Down Expand Up @@ -116,11 +116,11 @@ def GetEcardBills(session:requests.Session, _QueryDate:str|list[str]|tuple[str,s
month_list = set([datetime.fromisoformat(query_date).date().replace(day=1).isoformat() for query_date in _QueryDate]) # 收集需要查询的月份
ret = []
for _QueryMonth in month_list:
ret.append([entry # 头尾月份检测是否在日期区间内
ret.extend([entry
for entry in _GetMonth(session,account,_QueryMonth)
if entry['occtime'][:10] in _QueryDate])

if isinstance(_QueryDate, tuple):
elif isinstance(_QueryDate, tuple):
_QueryDate = ( # 格式化日期区间
datetime.strptime(_QueryDate[0].replace('/','-'), '%Y-%m-%d').date().isoformat(),
datetime.strptime(_QueryDate[1].replace('/','-'), '%Y-%m-%d').date().isoformat()
Expand All @@ -129,11 +129,11 @@ def GetEcardBills(session:requests.Session, _QueryDate:str|list[str]|tuple[str,s
month_list = get_yyyy_mm_between_dates(_QueryDate)
for _QueryMonth in month_list:
if _QueryMonth is month_list[0] or _QueryMonth is month_list[-1]:
ret.append([entry # 头尾月份检测是否在日期区间内
ret.extend([entry # 头尾月份检测是否在日期区间内
for entry in _GetMonth(session,account,_QueryMonth)
if is_inbetween_2_dates(entry['occtime'][:10],_QueryDate)])
else:
ret.append(_GetMonth(session,account,_QueryMonth))
ret.extend(_GetMonth(session,account,_QueryMonth))

elif isinstance(_QueryDate, str):
_QueryDate.replace('/','-')
Expand Down
14 changes: 11 additions & 3 deletions test_basic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from hust_login import HustPass
import logging
import json
logging.basicConfig(level=logging.DEBUG,\
format='[%(levelname)s] %(message)s')

Uname = input('Uid:')
Upass = input('Pwd:')
# Uname = input('Uid:')
# Upass = input('Pwd:')

# secret.txt 被ignore了
with open('secret.txt', 'r') as f:
Uname,Upass = f.read().split('\n')


with HustPass(Uname, Upass) as s:
print(s.QueryEcardBills('2023-05-20'))
with open('res.json','w') as f:
f.write(json.dumps(s.QueryEcardBills(
['2023-05-06','2023-06-06','2022-10-10']), ensure_ascii=False))


0 comments on commit 07e7d2f

Please sign in to comment.