Last active
June 15, 2018 02:33
-
-
Save KMConner/788baa5b724df893bad190337ffe7f5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
import os | |
import zipfile | |
import json | |
from typing import List | |
import time | |
from requests.auth import HTTPDigestAuth | |
ZIP_FILE_NAME = 'submitData.zip' | |
if __name__ == "__main__": | |
zip_files: List[str] = [] | |
zip_files.append('./mySet.ml') | |
zip_files.append('./mySet.mli') | |
zip_files.append('./parser.mly') | |
zip_files.append('./syntax.ml') | |
zip_files.append('./typing.ml') | |
zip_files.append('./main.ml') | |
zip_files.append('./environment.ml') | |
zip_files.append('./environment.mli') | |
zip_files.append('./eval.ml') | |
zip_files.append('./lexer.mll') | |
if len(zip_files) == 0: | |
print("No Files Specified.") | |
exit(2) | |
with zipfile.ZipFile(ZIP_FILE_NAME, 'w', compression=zipfile.ZIP_DEFLATED) as newzip: | |
for file in zip_files: | |
newzip.write(file, arcname=os.path.basename(file)) | |
url = 'https://www.fos.kuis.kyoto-u.ac.jp/~yuu/classes/le3b2018/api/post.cgi' | |
digest: HTTPDigestAuth = HTTPDigestAuth('id', 'pw') | |
fff = {'report_file': ('task1.ml.zip', open( | |
ZIP_FILE_NAME, 'rb'), 'application/zip')} | |
ddd = [('report_id', 'report2'), | |
('ex[]', 'Ex.3.2.1'), # Required | |
('ex[]', 'Ex.3.2.2'), # Star 2 | |
# ('ex[]', 'Ex.3.2.3'), # Star 1 | |
# ('ex[]', 'Ex.3.2.4'), # Star 2 | |
# ('ex[]', 'Ex.3.3.1'), # Required | |
# ('ex[]', 'Ex.3.3.2'), # Star 2 | |
# ('ex[]', 'Ex.3.3.3'), # Star 2 | |
# ('ex[]', 'Ex.3.3.4'), # Star 2 | |
# ('ex[]', 'Ex.3.4.1'), # Required | |
# ('ex[]', 'Ex.3.4.2'), # Star 2 | |
# ('ex[]', 'Ex.3.4.3'), # Star 1 | |
# ('ex[]', 'Ex.3.4.4'), # Star 1 | |
# ('ex[]', 'Ex.3.4.5'), # Star 1 | |
# ('ex[]', 'Ex.3.4.6'), # Star 1 | |
# ('ex[]', 'Ex.3.5.1'), # Required | |
# ('ex[]', 'Ex.3.5.2'), # Star 2 | |
# ('ex[]', 'Ex.3.6.1'), # Star 2 | |
# ('ex[]', 'Ex.3.6.2'), # Star 1 | |
# ('ex[]', 'Ex.3.6.3'), # Star 1 | |
# ('ex[]', 'Ex.3.6.4'), # Star 3 | |
# ('ex[]', 'Ex.3.6.5'), # Star 2 | |
] | |
hhh = { | |
'Referer': 'https://www.fos.kuis.kyoto-u.ac.jp/~yuu/classes/le3b2018/post/', | |
'Host': 'www.fos.kuis.kyoto-u.ac.jp'} | |
session = requests.Session() | |
session.auth = digest | |
# req = requests.Request("POST", url, files=fff, data=ddd, headers=hhh).prepare() | |
# print(req.body) | |
# print(req.headers) | |
r: requests.Response = session.post( | |
url, files=fff, data=ddd, auth=digest, headers=hhh) | |
# print(r.request.headers) | |
# print(r.status_code) | |
# print(r.url) | |
# print(r.headers) | |
if r.status_code == 200: | |
print('Submission Succeeded! Getting test result in a moment...') | |
for i in range(3): | |
time.sleep(3) | |
response: requests.Response = requests.get( | |
'https://www.fos.kuis.kyoto-u.ac.jp/~yuu/classes/le3b2018/api/user.cgi?type=status&status=record&log=true&report=report2', | |
auth=digest) | |
# print(response.status_code) | |
json_dict: dict = json.loads(response.text)[0] | |
if ('report' in json_dict.keys() and | |
'report2' in json_dict['report'].keys() and | |
'log' in json_dict['report']['report2'].keys()): | |
log_dict: dict = json_dict['report']['report2']['log'] | |
if 'message' in log_dict.keys(): | |
print('Message: ') | |
print(log_dict['message']) | |
if 'error' in log_dict.keys(): | |
print('Error') | |
print(log_dict['error']) | |
break | |
elif ('test' in log_dict.keys() and | |
'passed' in log_dict['test'].keys() and | |
'number' in log_dict['test'].keys()): | |
print('Test Results: %s / %s' % | |
(log_dict['test']['passed'], log_dict['test']['number'])) | |
break | |
else: | |
print('Submission Failed!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment