-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapi.py
33 lines (28 loc) · 1.4 KB
/
api.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse, json
from WuLpisApiClass import WuLpisApi
def file_parser(filepath, separator="="):
data = {}
for line in open(filepath, "r"):
line = line.rstrip('\n').split(separator)
data[line[0]] = line[1]
return data
if __name__ == '__main__':
parser=argparse.ArgumentParser()
parser.add_argument('-a', '--action', help="Which action in the programm should run", required=True)
parser.add_argument('-c', '--credfile', help='Path to the credentials file with username and password')
parser.add_argument('-p', '--password')
parser.add_argument('-u', '--username')
parser.add_argument('-s', '--sessiondir', help='Dir where the sessions should be stored')
parser.add_argument('-pp', '--planobject', help="Study plan object in which the correspondending course can be found (Studienplanpunkt")
parser.add_argument('-lv', '--course', help="Course ID for which the registration should be done")
parser.add_argument('-lv2', '--course2', help="Fallback (second) Course ID")
args=parser.parse_args()
username = file_parser(args.credfile)["username"] if args.credfile else args.username
password = file_parser(args.credfile)["password"] if args.credfile else args.password
api = WuLpisApi(username, password, args, args.sessiondir)
method = getattr(api, args.action, None)
if callable(method):
method()
print json.dumps(api.getResults(), sort_keys=True, indent=4)