diff --git a/moondb.py b/moondb.py index 038bd6ae8439a785d5719fd0d737af0da1209587..b9b3c941c60a9c49e84afafb6f602db69e77648d 100755 --- a/moondb.py +++ b/moondb.py @@ -65,25 +65,41 @@ def get_samplingtechnique(): class Filter: def __init__(self): - self.mission = None - self.landmark = None - self.specimenType = None - self.samplingTechnique = None - self.analyzedMaterial = None - self.analyte = None - self.analysisMethod = None + self.mission = [] + self.landmark = [] + self.specimenType = [] + self.samplingTechnique = [] + self.analyzedMaterial = [] + self.analyte = [] + self.analysisMethod = [] def _toJSON(self): - return json.dumps(self, default=lambda o: o.__dict__,sort_keys=True, indent=4) + #indent=4 + return json.dumps(self, default=lambda o: o.__dict__,sort_keys=True,separators=(",", ":")) def get_results(self): - print self._toJSON() + #print self._toJSON() + #print _url('/data/'+self._toJSON() ) resp = requests.get(_url('/data/'+self._toJSON() )) - + res_list = [] + + for r in resp.json()['results']: + rd = dict(r) + res_list.append(rd) + return res_list - class Mission: def __init__(self,name): self.name = name +class Specimen: + def __init__(self): + self.specimenCode = "" + self.specimenName = "" + self.parentSpecimen = "" + self.childSpecimens = "" + self.specimenType = "" + #self.samplingTechnique":null,"mission":"Apollo 12","landmark":null,"lunarStation":null,"returnContainer":null,"weight":null,"pristinity":null,"pristinityDate":null,"description":null} + + class AnalysisMethos: def __init__(self,code,name): self.name = name @@ -99,10 +115,21 @@ if __name__ == "__main__": m = get_missions() print m f = Filter() - f.mission = ["Apollo 11"] - f.specimenType = ["Breccia"] + f.specimenType = ["SOIL"] + f.analyte = ["H2O","Ti"] + f.mission = ["Apollo 11"] + print 80*"#" #print f.toJSON() - print f.get_results() + results = f.get_results() + for r in results: + print r + print "********" + this_res = r['dataResults'][0] + print this_res + var = this_res['variable'] + val = this_res['value'] + unit = this_res['unit'] + print var,": ",val,unit