|
| 1 | +import requests, json |
| 2 | + |
| 3 | +def submit(submitterEmail,secret,key,submission_part, all_parts, data): |
| 4 | + submission = { |
| 5 | + "assignmentKey": key, |
| 6 | + "submitterEmail": submitterEmail, |
| 7 | + "secret": secret, |
| 8 | + "parts": {} |
| 9 | + } |
| 10 | + for part in all_parts: |
| 11 | + if part == submission_part: |
| 12 | + submission["parts"][part] = {"output": data} |
| 13 | + else: |
| 14 | + submission["parts"][part] = dict() |
| 15 | + response = requests.post('https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1', data=json.dumps(submission)) |
| 16 | + if response.status_code == 201: |
| 17 | + print ("Submission successful, please check on the coursera grader page for the status") |
| 18 | + print ("-------------------------") |
| 19 | + print (response.text) |
| 20 | + print ("-------------------------") |
| 21 | + else: |
| 22 | + print ("Something went wrong, please have a look at the reponse of the grader") |
| 23 | + print ("-------------------------") |
| 24 | + print (response.text) |
| 25 | + print ("-------------------------") |
| 26 | + |
| 27 | +def submitAll(submitterEmail,secret,key,parts_and_data): |
| 28 | + submission = { |
| 29 | + "assignmentKey": key, |
| 30 | + "submitterEmail": submitterEmail, |
| 31 | + "secret": secret, |
| 32 | + "parts": {} |
| 33 | + } |
| 34 | + for part, output in parts_and_data.items(): |
| 35 | + if output is not None: |
| 36 | + submission["parts"][part] = {"output": output} |
| 37 | + else: |
| 38 | + submission["parts"][part] = dict() |
| 39 | + response = requests.post('https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1', data=json.dumps(submission)) |
| 40 | + if response.status_code == 201: |
| 41 | + print ("Submission successful, please check on the coursera grader page for the status") |
| 42 | + print ("-------------------------") |
| 43 | + print (response.text) |
| 44 | + print ("-------------------------") |
| 45 | + else: |
| 46 | + print ("Something went wrong, please have a look at the reponse of the grader") |
| 47 | + print ("-------------------------") |
| 48 | + print (response.text) |
| 49 | + print ("-------------------------") |
0 commit comments