forked from hinnuryuu/UJN-Library-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_seat_id.py
More file actions
59 lines (56 loc) · 2.25 KB
/
get_seat_id.py
File metadata and controls
59 lines (56 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
from libapi import *
from libapi.utils import *
settings_exist = False
for filename in os.listdir():
if filename == 'settings.json':
settings_exist = True
break
if settings_exist:
with open('settings.json', 'r', encoding='utf-8') as f:
try:
settings_information = eval(str(json.loads(f.read())))
except json.JSONDecodeError:
print("配置文件出错,请打开 settings_file_generator.py 重新生成一份配置模板")
exit(1)
else:
print("配置文件出错,请打开 settings_file_generator.py 重新生成一份配置模板")
exit(1)
username = settings_information['data'][0]['username']
password = settings_information['data'][0]['password']
try:
p = libapi(username, password)
except LoginException as e:
print("%s\n本程序已中止您的操作!" % e.err)
exit(1)
except ConnectionError:
print("检查一下网络呢亲,这边完全无法收到电波呢,程序即将中止...")
exit(1)
else:
room_order = 1
library_information = p.filters()
print("UJN图书室的信息如下:")
for room in library_information['data']['rooms']:
print("%d.%s 校区:%s 楼层:%d" % (room_order, room[1], "东校区" if room[2] == 1 else "西校区", room[3]))
room_order += 1
try:
choice = int(input("输入序号确定图书室:"))
except ValueError:
print("输入错误,程序中止")
exit(1)
else:
if 1 <= choice < room_order:
room_id = library_information['data']['rooms'][choice - 1][0]
seat_number_limitation = limit_seat_number(room_id)
seat_num = input(
"输入要预定的座位号(当前阅览室的座位号接受范围为 {}~{}):"
.format(seat_number_limitation[0], seat_number_limitation[1])
)
seat_id = p.getSeatIDbyNum(str(room_id), str(seat_num))
if seat_id is not None:
print("获取成功!请记下您的座位id:%d" % seat_id)
else:
print("获取失败,因为这是不存在的座位号")
else:
print("输入错误,程序中止")
exit(1)