forked from SmartDataAnalytics/HORUS-NER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.py
48 lines (40 loc) · 1.28 KB
/
metadata.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
import urllib
import urllib2
class Web4MexCreator:
token = ''
resultPath = ''
def __init__(self, path="SampleWeb4MexFile.txt"):
self.token = self.getToken()
#self.token = '05635b00-31ab-488b-ad97-3838637f3e8a'
self.resultPath = path
def getToken(self):
request = urllib2.Request('http://52.173.249.140:3011/token')
response = urllib2.urlopen(request)
return response.read()
def setAuthorName(self, author):
headers = {"Accept" : "*/*"}
request = urllib2.Request('https://52.173.249.140:3011/%s/authorEmail?%s' %(self.token, author))
request.add_header("Accept", "*/*")
response = urllib2.urlopen(request)
if response.code != 200:
return False
else:
return True
def getResult(self):
url = 'http://52.173.249.140:3011/%s/serialize?format=ttl' % (self.token)
request = urllib2.Request(url)
response = urllib2.urlopen(request)
if response.code != 200:
return False
else:
content = response.read();
file = open(self.resultPath, "w")
file.write(content)
file.close
return True
if __name__ == '__main__':
creator = Web4MexCreator()
print creator.token
#creator.setAuthorName("testname")
if not creator.getResult():
print "no valid response from Web4Mex. File could not be created"