-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusub.py
59 lines (47 loc) · 1.31 KB
/
usub.py
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 re
import sys
from pathlib import Path
import colorama
import getargs
import session
import submit
import submitutil
import status
def main():
colorama.init()
args = getargs.getargs()
TYPE = 'status'
_prob = args.problem
CPID = None
match_link = re.search(r'cpid=(\d+)', _prob)
match_cpid = re.match(r'(\d+)', _prob)
if match_link is not None:
CPID = match_link.group(1)
elif match_cpid is not None:
CPID = match_cpid.group(1)
else:
raise ValueError('Invalid CPID')
# add for verbose in future
# sys.stderr.write(f'found cpid of {CPID}\n')
if args.fresh:
session.invalidate_sessid()
if args.file is not None:
TYPE = 'submission'
sid = '-1'
if TYPE == 'status':
sid = submit.get_sid(CPID)
elif TYPE == 'submission':
FILE = Path(args.file)
LANG = args.lang
CODE = None
if not Path(FILE).is_file():
raise FileNotFoundError(f'cant find file: {FILE}')
if LANG == 'infer':
FILEEXT = Path(FILE).resolve(strict=True).suffix.strip('.')
CODE = submitutil.infer(FILEEXT)
else:
CODE = submitutil.get_code(LANG)
sid = submit.submit(FILE, CODE, CPID)
status.display_status(sid)
if __name__ == '__main__':
main()