Commit d7e77f21 authored by Kiste's avatar Kiste
Browse files

Don't need to go through folders actually

parent 3e32c66d
......@@ -4,19 +4,19 @@
from setuptools import setup
setup(
name = 'studsauger',
version = '1.0',
description = 'Stud.IP download tool',
url = 'https://git.finf.uni-hannover.de/kiste/studsauger',
author = 'Christian Buschau',
author_email = 'christian.buschau@stud.uni-hannover.de',
packages = ['studsauger'],
install_requires = [
name='studsauger',
version='1.0',
description='Stud.IP download tool',
url='https://git.finf.uni-hannover.de/kiste/studsauger',
author='Christian Buschau',
author_email='christian.buschau@stud.uni-hannover.de',
packages=['studsauger'],
install_requires=[
'keyring',
'requests',
'PyYAML'
],
entry_points = {
entry_points={
'console_scripts': [
'studsauger = studsauger.studsauger:main'
]
......
# -*- coding: utf-8 -*-
import json
import os
import shutil
import time
......@@ -17,60 +18,47 @@ def logik(path, user, password, blacklist, allsemesters):
newtimestamp = str(int(time.time()))
if not os.path.isfile(path + '/.timestamp'):
neu = True
with open(path + '/.timestamp', 'w+') as timestampfile:
timestampfile.write(newtimestamp)
timestamp = newtimestamp
timestamp = ''
else:
neu = False
with open(path + '/.timestamp', 'r+') as timestampfile:
timestamp = timestampfile.read()
timestamp = '/' + timestampfile.read()
timestampfile.seek(0)
timestampfile.write(newtimestamp)
timestampfile.truncate()
s = requests.Session()
s.auth = (user, password)
jsemester = s.get(BASEURL + '/courses/semester')
session = requests.Session()
session.auth = (user, password)
jsemester = session.get(BASEURL + '/courses/semester')
if allsemesters:
for semester in jsemester.json()['semesters']:
holsemester(path + '/' + semester['title'].replace('/', ''), s, blacklist, neu, timestamp, semester)
holsemester(path + '/' + semester['title'].replace('/', ''), session, blacklist, timestamp, semester)
else:
holsemester(path, s, blacklist, neu, timestamp, jsemester.json()['semesters'][-1])
holsemester(path, session, blacklist, timestamp, jsemester.json()['semesters'][-1])
def holsemester(path, s, blacklist, neu, timestamp, cursemester):
jcourses = s.get(BASEURL + '/courses/semester/' + cursemester['semester_id'])
def holsemester(path, session, blacklist, timestamp, cursemester):
jcourses = session.get(BASEURL + '/courses/semester/' + cursemester['semester_id'])
for course in jcourses.json()['courses']:
if course['title'] in blacklist:
continue
mkdir(path + '/' + course['title'])
if neu:
jfolder = s.get(BASEURL + '/documents/' + course['course_id'] + '/folder')
for folder in jfolder.json()['folders']:
holordner(path, s, course, folder)
else:
jnew = s.get(BASEURL + '/documents/' + course['course_id'] + '/new/' + timestamp)
print(BASEURL + '/documents/' + course['course_id'] + '/new' + timestamp)
jnew = session.get(BASEURL + '/documents/' + course['course_id'] + '/new' + timestamp)
try:
for document in jnew.json()['documents']:
holdatei(path, s, course, document)
holdatei(path, session, course, document)
except json.decoder.JSONDecodeError:
print('Die Veranstaltung "' + course['title'] + '" hat keine Dokumente.')
def holordner(path, s, course, folder):
jfiles = s.get(BASEURL + '/documents/' + course['course_id'] + '/folder/' + folder['folder_id'])
for subfolder in jfiles.json()['folders']:
holordner(path, s, course, subfolder)
for document in jfiles.json()['documents']:
holdatei(path, s, course, document)
def holdatei(path, s, course, document):
def holdatei(path, session, course, document):
target = path + '/' + course['title'] + '/' + document['filename']
download = s.get(BASEURL + '/documents/' + document['document_id'] + '/download', stream=True)
download = session.get(BASEURL + '/documents/' + document['document_id'] + '/download', stream=True)
if download.status_code == 200:
print(path + '/' + course['title'] + '/' + document['filename'])
with open(target, 'wb') as file:
......
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