-
Notifications
You must be signed in to change notification settings - Fork 3
/
submit.py
executable file
·34 lines (29 loc) · 1.02 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
#!/bin/bash
import urllib2
import MultipartPostHandler
import datetime
from os import remove
def answerLine(number,answer):
return str(number)+' top_docs.'+str(number)+' '+answer
def formatAnswers(numbers,answers):
return '<s> <s>\n'+"\n".join(map(answerLine,numbers,answers))
def submit(netid,answers):
answersFile='tmp-answers.txt'
answersHandle=open(answersFile,'w')
answersHandle.write(answers)
answersHandle.close()
answersHandle=open(answersFile,'rb')
params= { 'netid':netid,
'predictions': answersHandle
}
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
urllib2.install_opener(opener)
req = urllib2.Request('http://www.cs.cornell.edu/w8/~luwang/cs4740_QA/getFile',params)
response = urllib2.urlopen(req).read().strip()
answersHandle.close()
remove(answersFile)
return response+'\n(Submitted at '+datetime.datetime.now().ctime()+')'
def main():
print formatAnswers(['398','248'],['the day after Christmas','Document Freedom Day'])
if __name__ == "__main__":
main()