forked from claimed-framework/component-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rklib.py
59 lines (55 loc) · 2.48 KB
/
rklib.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
import requests, json
import zipfile
import os
def submit(submitterEmail,secret,key,submission_part, all_parts, data):
submission = {
"assignmentKey": key,
"submitterEmail": submitterEmail,
"secret": secret,
"parts": {}
}
for part in all_parts:
if part == submission_part:
submission["parts"][part] = {"output": data}
else:
submission["parts"][part] = dict()
response = requests.post('https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1', data=json.dumps(submission))
if response.status_code == 201:
print ("Submission successful, please check on the coursera grader page for the status")
print ("-------------------------")
print (response.text)
print ("-------------------------")
else:
print ("Something went wrong, please have a look at the reponse of the grader")
print ("-------------------------")
print (response.text)
print ("-------------------------")
def submitAll(submitterEmail,secret,key,parts_and_data):
submission = {
"assignmentKey": key,
"submitterEmail": submitterEmail,
"secret": secret,
"parts": {}
}
for part, output in parts_and_data.items():
if output is not None:
submission["parts"][part] = {"output": output}
else:
submission["parts"][part] = dict()
response = requests.post('https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1', data=json.dumps(submission))
if response.status_code == 201:
print ("Submission successful, please check on the coursera grader page for the status")
print ("-------------------------")
print (response.text)
print ("-------------------------")
else:
print ("Something went wrong, please have a look at the reponse of the grader")
print ("-------------------------")
print (response.text)
print ("-------------------------")
def zipit(target, path):
zipf = zipfile.ZipFile(target, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(path):
for file in files:
zipf.write(os.path.join(root, file))
zipf.close()