-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.py
executable file
·39 lines (34 loc) · 1.3 KB
/
submit.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
#!/usr/bin/python
import os.path
import subprocess
import sys
import urllib
KEY_FILE = "submit.token"
def main(filename):
# Prompt for key if missing
if not os.path.exists(KEY_FILE):
print "Please visit http://css.csail.mit.edu/6.858/2014/labs/handin.html"
print "and enter your API key."
key = raw_input("Key: ").strip()
with open(KEY_FILE, "w") as f:
f.write(key + "\n")
print "API key written to %s" % KEY_FILE
# Read the key.
with open(KEY_FILE) as f:
key = f.read().strip()
# Shell out to curl. urllib2 doesn't deal with multipart attachments. Throw
# away the output; you just get a random HTML page.
with open("/dev/null", "a") as null:
subprocess.check_call(["curl", "-f",
"-F", "file=@%s" % filename,
"-F", "key=%s" % key,
"http://6858.scripts.mit.edu/submit/handin.py/upload"],
stdout=null, stderr=null)
print "Submitted %s." % filename
print "Please visit http://css.csail.mit.edu/6.858/2014/labs/handin.html"
print "to verify the upload."
if __name__ == "__main__":
if len(sys.argv) < 2:
print "Usage: %s TARBALL" % sys.argv[0]
sys.exit(1)
main(sys.argv[1])