-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreditUploader.py
106 lines (80 loc) · 3.23 KB
/
CreditUploader.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun May 7 02:22:17 2017
@author: christopher
"""
from os.path import basename as pbasename
from os import getcwd
from os import scandir
from sys import argv
from re import compile as rcompile
from muesli import MuesliApi
from gmdata_managment import FolderManager as FM
#from gmdata_managment import findStudentInList as fStudLi
def extractSheetNr(fName):
return int(pbasename(fName).split('.')[0].split('_')[1])
def getAllStudentNames(eCreditFile):
res = []
with open(eCreditFile) as fd:
for line in fd:
res.append(line.split('|')[1:-1][0].strip())
return res
def uploadCreditFile(creditFile, fm):
print('Upload %s to MÜSLI.' % creditFile)
sheetNr = extractSheetNr(creditFile)
with MuesliApi(acc = fm.getMÜSLIAcc()) as mapi:
tids = fm.getTIDs()
infos = fm.getTutMetaInfo()
for tid in tids:
for info in infos:
if tid == info['ID']:
print(info)
result, students = mapi.uploadCredits(info, creditFile, sheetNr)
print()
print('Not matched - maybe some of them didn\'t upload sth:')
for student in students:
print(student)
print('_____________________')
for r,k in result.items():
print(r, k)
def uploadExternalCreditFile(eCreditFile, fm):
print('Upload %s to MÜSLI.' % eCreditFile)
sheetNr = extractSheetNr(eCreditFile)
eTut = pbasename(eCreditFile).split('.')[0].split('_')[3].replace('-', ' ')
print(eTut)
names = getAllStudentNames(eCreditFile)
with MuesliApi(acc = fm.getMÜSLIAcc()) as mapi:
tids = fm.getETIDs()
infos = [info for info in fm.getETutMetaInfo() if info['ExtTut'] == eTut]
for tid in tids:
for info in infos:
if len(names) == 0:
print('Nothing to match!')
return
if tid == info['ID']:
print(info)
result, students = mapi.uploadCredits(info, eCreditFile, sheetNr)
print()
print('Matched: ')
for r,k in result.items():
names.remove(r)
print(r, k)
print('Still need to match:')
for name in names:
print(name)
if __name__ == '__main__':
print('Credit Upload')
if len(argv) == 2:
uploadCreditFile(argv[1])
else:
folder = getcwd()
fm = FM()
for entry in scandir(folder):
if entry.is_file():
print()
extPatternStr = 'AllCredits_\d\d_%s_.*\.txt' % fm.getTFirstName()
if rcompile('AllCredits_\d\d\.txt').match(entry.name):
uploadCreditFile(entry.path, fm)
elif rcompile(extPatternStr).match(entry.name):
uploadExternalCreditFile(entry.path, fm)