7
7
from time import time
8
8
import subprocess
9
9
import json
10
+ from mglib .mglib import obj_from_url , async_rest_api
10
11
11
12
12
-
13
- API_URL = "http://api.metagenomics.anl.gov/1"
13
+ API_URL = "https://api.mg-rast.org/1"
14
14
15
15
SKIP = ["48f15d5aae95892edb9bae03988573fa" ,
16
16
'3bfa44d3dad4e2af12bab2601cfa8138' ,
@@ -34,21 +34,6 @@ def sanitize(c):
34
34
clist = clist [:i ] + ["" .join (clist [i :j + 1 ])[1 :- 1 ]] + clist [j + 1 :]
35
35
return " " .join (clist )
36
36
37
- def getmeajsonobject (url ):
38
- '''places HTTP request for url and parses the returned JSON object'''
39
- if VERBOSE :
40
- sys .stderr .write ("Retrieving %s\n " % url )
41
- try :
42
- opener = urllib2 .urlopen (url )
43
- except urllib2 .HTTPError , e :
44
- print "Error with HTTP request: %d %s\n %s" % (e .code , e .reason , e .read ())
45
- return None
46
- opener .addheaders = [('User-agent' , 'API-testing.py' )]
47
-
48
- jsonobject = opener .read ()
49
- jsonstructure = json .loads (jsonobject )
50
- return jsonstructure
51
-
52
37
def print_tests (testlist ):
53
38
for test in testlist :
54
39
callhash , call , name , name2 , description = test
@@ -77,8 +62,14 @@ def check_ok(stem, dir1, blesseddir):
77
62
elif len (f2 ) == 0 :
78
63
return False , "emptyreference"
79
64
elif len (f1 ) > 0 and len (f2 ) > 0 and f1 [0 ] == "{" and f2 [0 ] == "{" :
80
- j1 = json .loads (f1 )
81
- j2 = json .loads (f2 )
65
+ try :
66
+ j1 = json .loads (f1 )
67
+ except UnicodeDecodeError :
68
+ j1 = json .loads (f1 .decode ('latin-1' ))
69
+ try :
70
+ j2 = json .loads (f2 )
71
+ except UnicodeDecodeError :
72
+ j2 = json .loads (f2 .decode ('latin-1' ))
82
73
if "date" in j1 .keys ():
83
74
j1 ["date" ] = ""
84
75
if "date" in j2 .keys ():
@@ -166,12 +157,12 @@ def run_tests(testlist):
166
157
def get_example_calls (base_url ):
167
158
topleveljsonobjects = {}
168
159
requestlist = []
169
- json_api_calls = getmeajsonobject (base_url )
160
+ json_api_calls = obj_from_url (base_url )
170
161
listofapiurls = [resources ["url" ] for resources in json_api_calls ["resources" ]]
171
162
for resourceurl in listofapiurls :
172
163
if VERBOSE :
173
164
sys .stderr .write ("resourceurl: " + resourceurl + "\n " )
174
- topleveljsonobjects [resourceurl ] = getmeajsonobject (resourceurl )
165
+ topleveljsonobjects [resourceurl ] = obj_from_url (resourceurl )
175
166
if VERBOSE :
176
167
print "listofapiurls: " , listofapiurls
177
168
for resource in listofapiurls :
0 commit comments