This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·71 lines (60 loc) · 1.49 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
#!.venv/bin/python
import requests as rq
import json
import sys
import random
import string
import secrets
import logging
import click
import csv
from pathlib import Path
from cli.problem import problem
from cli.submission import submission
from core.util import API_BASE, load_user
logging.basicConfig(level=logging.DEBUG)
@click.group()
@click.option(
'--user',
'-u',
default='first_admin',
help='which user to login',
)
@click.pass_context
def command_entry(ctx, user):
'''
the entry of noj cli(?
'''
ctx.ensure_object(dict)
ctx.obj['user'] = load_user(user)
@command_entry.command()
@click.argument('users')
def create_user(users):
'''
create users from file
'''
users = Path(users)
if not users.exists():
print(f'{users} not found!')
return
if users.suffix == '.csv':
with open(users) as f:
_users = csv.DictReader(f)
users = _users
elif users.suffix == '.json':
users = json.loads(users.read_text())
elif users.suffix == '.xls':
print('haven\'t implemented')
return
for u in users:
rq.post(f'{API_BASE}/auth/signup', json=u)
if __name__ == "__main__":
command_entry.add_command(problem)
command_entry.add_command(submission)
try:
rq.get(f'{API_BASE}/test/')
except rq.ConnectionError:
print('Can not connect to NOJ API.\n'
'Do you set the correct URL? or the NOJ is up now?')
exit(0)
command_entry()