3 from manifold.manifoldresult import ManifoldResult
4 from manifold.manifoldapi import ManifoldAPI
9 # turn this on if you want to work offline
15 def __init__ (self, auth):
17 self.hash_by_subject={}
20 offline_filename="offline-metadata.json"
23 with file(offline_metadata) as f:
24 self.hash_by_subject=json.loads(f.read())
27 print "metadata.work_offline: failed to decode %s"%offline_filename
28 manifold_api = ManifoldAPI(self.auth)
29 fields = ['table', 'column.column',
30 'column.description','column.header', 'column.title',
31 'column.unit', 'column.info_type',
32 'column.resource_type', 'column.value_type',
33 'column.allowed_values', 'column.platforms.platform',
34 'column.platforms.platform_url']
35 rows_result = manifold_api.Get('metadata:table', [], [], fields)
36 rows = rows_result.ok_value()
38 print "Failed to retrieve metadata",rows_result.error()
39 self.hash_by_subject = dict ( [ (row['table'], row) for row in rows ] )
40 # save for next time we use offline mode
42 with file(offline_filename,'w') as f:
43 f.write(json.dumps(self.hash_by_subject))
46 return json.dumps(self.hash_by_subject)
48 def details_by_subject (self, subject):
49 return self.hash_by_subject[subject]
51 def sorted_fields_by_subject (self, subject):
52 return self.hash_by_subject[subject]['columns'].sort()