This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
aoxiangRobot
executable file
·149 lines (105 loc) · 4.14 KB
/
aoxiangRobot
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argh
from argh import arg
@arg('-t', '--term', help='terms, for example: 19', nargs='+')
def grade(**kwargs):
"""
获取考试成绩
"""
from src.grade import Grade
username = kwargs['username']
password = open(kwargs['password']).read().strip()
g = Grade(username=username, password=password)
if kwargs['term']:
g.output(*kwargs['term'])
else:
g.output()
@arg('-t', '--term', help='terms, for example: 19', nargs='+', required=True)
def exam(**kwargs):
"""
获取考试安排
"""
from src.exam import Exam
username = kwargs['username']
password = open(kwargs['password']).read().strip()
e = Exam(username=username, password=password)
e.output(*kwargs['term'])
@arg('-t', '--term', help='terms, for example: 19', required=True)
def courses(**kwargs):
"""
获取我的课程信息
"""
from src.classTable import ClassTable
username = kwargs['username']
password = open(kwargs['password']).read().strip()
e = ClassTable(username=username, password=password)
e.output(kwargs['term'])
def me(**kwargs):
"""
获取当前账号信息
"""
from rich.console import Console
from rich.table import Table
from src.netreq.aoxiang import Aoxiang
username = kwargs['username']
password = open(kwargs['password']).read().strip()
console = Console()
res = Aoxiang(username=username, password=password).userInfo
for i in res:
table = Table(title=i, show_header=False, width=120)
info = list(res[i].items())
if len(info) % 2:
info.append(('', ''))
table.add_column('', width=20)
table.add_column('', width=40)
table.add_column('', width=20)
table.add_column('', width=40)
for x in range(0, len(info), 2):
table.add_row(*(info[x] + info[x + 1]))
table.row_styles = ['none', 'dim']
console.print(table)
@arg('-s', '--start', help='time start, for example: 2020-9-1, today by default')
@arg('-e', '--end', help='time end, for example: 2020-12-31, today + 180 days by default')
@arg('-o', '--output', help='output classtable to the file in `ics` format', required=True)
@arg('-a', '--alarm', help='alarm before class, default: 20, set 0 to disable alarm', default=20)
def classTable(**kwargs):
"""
获取课表
"""
import os
from src import log
from src.classTable import ClassTable
if os.path.exists(kwargs['output']):
if not log.yes_or_no(f'{kwargs["output"]} exists, overwrite it?'):
log.e('Abort.')
username = kwargs['username']
password = open(kwargs['password']).read().strip()
ct = ClassTable(username=username, password=password)
ct.export(kwargs['start'], kwargs['end'], **kwargs)
@arg('-p', '--province', default=None, help='对应疫情填报中的省,在学校/在西安可不填')
@arg('-c', '--city', default=None, help='对应疫情填报中的市,直辖市填市辖区或县,在学校/在西安可不填')
@arg('-l', '--location', default='在学校', help='对应疫情填报中的当前位置(在学校/在西安)或区/县字段,查看所有允许的位置,看:`http://yqtb.nwpu.edu.cn/wx/js/eams.area.data.js`')
def yqtb(**kwargs):
"""
疫情填报
"""
from rich.console import Console
from rich.table import Table
from src.netreq.aoxiang import Aoxiang
username = kwargs['username']
password = open(kwargs['password']).read().strip()
res = Aoxiang(username, password).yqtb(province=kwargs['province'], city=kwargs['city'], location=kwargs['location'])
table = Table(title='Result')
table.add_column('A')
table.add_column('B')
for i in res:
table.add_row(i, res[i])
table.row_styles = ['dim', 'none']
Console().print(table)
if __name__ == '__main__':
parser = argh.ArghParser()
parser.add_argument('-u', '--username', required=True, help='username')
parser.add_argument('-p', '--password', required=True, help='password FILE path')
parser.add_commands([grade, exam, courses, classTable, me, yqtb])
parser.dispatch()