Commit 7b6f97bb authored by Kiste's avatar Kiste
Browse files

Semester choice

parent 5b6bc192
path:
user:
path: /home/user/studip
user: user
#password:
blacklist:
-
-
- Veranstaltung 1a
allsemesters: true
......@@ -5,6 +5,7 @@ import shutil
import requests
from colorama import Fore
import json
def mkdir(directory):
if not os.path.exists(directory):
os.makedirs(directory)
......@@ -12,13 +13,22 @@ def mkdir(directory):
BASEURL = 'https://studip.uni-hannover.de/plugins.php/restipplugin/api'
def logik(path, user, password, blacklist):
def logik(path, user, password, blacklist, allsemesters):
mkdir(path)
s = requests.Session()
s.auth = (user, password)
jsemester = s.get(BASEURL + '/courses/semester')
semester_id = jsemester.json()['semesters'][-1]['semester_id']
semester_title = jsemester.json()['semesters'][-1]['title']
if allsemesters:
for semester in jsemester.json()['semesters']:
fetchsemester(s, semester)
else:
fetchsemester(s, jsemester.json()['semesters'][-1])
def fetchsemester(s, cursemester):
semester_id = cursemester['semester_id']
semester_title = cursemester['title']
print(Fore.YELLOW + semester_title)
jcourses = s.get(BASEURL + '/courses/semester/' + semester_id)
for course in jcourses.json()['courses']:
......
......@@ -13,6 +13,7 @@ def main():
parser.add_argument('-u', '--user', help='Stud.IP Benutzername')
parser.add_argument('-pw', '--password', help='Stud.IP Passwort')
parser.add_argument('-b', '--blacklist', help='Blacklist für Veranstaltungen, mehrmals angeben für mehrere Veranstaltungen', action='append')
parser.add_argument('-a', '--allsemesters', help='Alle Semester statt nur dem aktuellen', action="store_true")
parser.add_argument('-c', '--config', help='YAML-Konfigurationsdatei, wird ohne Angabe in $XDG_CONFIG_HOME/studsauger/config.yaml oder $HOME/.config/studsauger/config.yaml gesucht')
args = parser.parse_args()
......@@ -70,8 +71,17 @@ def main():
blacklist = config['blacklist']
else:
blacklist = {}
if args.allsemesters:
allsemesters = True
elif 'allsemesters' in config:
allsemesters = config['allsemesters']
else:
print('Kein Semesterauswahl angegeben!')
exit(1)
print(allsemesters)
logik(path, user, password, blacklist)
logik(path, user, password, blacklist, allsemesters)
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment