diff --git a/Examples/Sample.py b/Examples/Sample.py index 772e3a8..bd941cd 100644 --- a/Examples/Sample.py +++ b/Examples/Sample.py @@ -40,7 +40,7 @@ allVars = read.getVariables() for x in allVars: - print x.VariableCode + ": " + x.VariableNameCV + print(x.VariableCode + ": " + x.VariableNameCV) @@ -48,15 +48,15 @@ allPeople = read.getPeople() for x in allPeople: - print x.PersonFirstName + " " + x.PersonLastName + print(x.PersonFirstName + " " + x.PersonLastName) try: - print "\n-------- Information about an Affiliation ---------" + print("\n-------- Information about an Affiliation ---------") allaff = read.getAllAffiliations() for x in allaff: - print x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID) + print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID)) except Exception as e: - print "Unable to demo getAllAffiliations", e + print("Unable to demo getAllAffiliations", e) # Get all of the SamplingFeatures from the database that are Sites try: @@ -64,28 +64,28 @@ numSites = len(siteFeatures) for x in siteFeatures: - print x.SamplingFeatureCode + ": " + x.SamplingFeatureName + print(x.SamplingFeatureCode + ": " + x.SamplingFeatureName) except Exception as e: - print "Unable to demo getSamplingFeaturesByType", e + print("Unable to demo getSamplingFeaturesByType", e) # Now get the SamplingFeature object for a SamplingFeature code try: sf = read.getSamplingFeatureByCode('USU-LBR-Mendon') - print sf - print "\n-------- Information about an individual SamplingFeature ---------" - print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n" - print "SamplingFeatureCode: " + sf.SamplingFeatureCode - print "SamplingFeatureName: " + sf.SamplingFeatureName - print "SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription - print "SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV - print "SamplingFeatureGeometry: %s" % sf.FeatureGeometry - print "Elevation_m: %s" % str(sf.Elevation_m) + print(sf) + print("\n-------- Information about an individual SamplingFeature ---------") + print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n") + print("SamplingFeatureCode: " + sf.SamplingFeatureCode) + print("SamplingFeatureName: " + sf.SamplingFeatureName) + print("SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription) + print("SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV) + print("SamplingFeatureGeometry: %s" % sf.FeatureGeometry) + print("Elevation_m: %s" % str(sf.Elevation_m)) except Exception as e: - print "Unable to demo getSamplingFeatureByCode: ", e + print("Unable to demo getSamplingFeatureByCode: ", e) #add sampling feature -print "\n------------ Create Sampling Feature --------- \n", +print("\n------------ Create Sampling Feature --------- \n") try: from odm2api.ODM2.models import SamplingFeatures newsf = SamplingFeatures() @@ -100,19 +100,19 @@ newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2" session.add(newsf) #session.commit() - print "new sampling feature added to database", newsf + print("new sampling feature added to database", newsf) except Exception as e : - print "error adding a sampling feature: " + str(e) + print("error adding a sampling feature: " + str(e)) # Drill down and get objects linked by foreign keys -print "\n------------ Foreign Key Example --------- \n", +print("\n------------ Foreign Key Example --------- \n",) try: # Call getResults, but return only the first result firstResult = read.getResults()[0] - print "The FeatureAction object for the Result is: ", firstResult.FeatureActionObj - print "The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj + print("The FeatureAction object for the Result is: ", firstResult.FeatureActionObj) + print("The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj) print ("\nThe following are some of the attributes for the Action that created the Result: \n" + "ActionTypeCV: " + firstResult.FeatureActionObj.ActionObj.ActionTypeCV + "\n" + "ActionDescription: " + firstResult.FeatureActionObj.ActionObj.ActionDescription + "\n" + @@ -121,11 +121,11 @@ "MethodName: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodName + "\n" + "MethodDescription: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodDescription) except Exception as e: - print "Unable to demo Foreign Key Example: ", e + print("Unable to demo Foreign Key Example: ", e) # Now get a particular Result using a ResultID -print "\n------- Example of Retrieving Attributes of a Time Series Result -------" +print("\n------- Example of Retrieving Attributes of a Time Series Result -------") try: tsResult = read.getTimeSeriesResultByResultId(1) print ( @@ -142,19 +142,19 @@ "SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName) except Exception as e: - print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e + print("Unable to demo Example of retrieving Attributes of a time Series Result: ", e) # Get the values for a particular TimeSeriesResult -print "\n-------- Example of Retrieving Time Series Result Values ---------" +print("\n-------- Example of Retrieving Time Series Result Values ---------") tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe # Print a few Time Series Values to the console # tsValues.set_index('ValueDateTime', inplace=True) try: - print tsValues.head() + print(tsValues.head()) except Exception as e: - print e + print(e) # Plot the time series @@ -173,4 +173,4 @@ ax.grid(True) plt.show() except Exception as e: - print "Unable to demo plotting of tsValues: ", e + print("Unable to demo plotting of tsValues: ", e) diff --git a/odm2api/ODM1_1_1/services/edit_service.py b/odm2api/ODM1_1_1/services/edit_service.py index 5a23642..352296e 100644 --- a/odm2api/ODM1_1_1/services/edit_service.py +++ b/odm2api/ODM1_1_1/services/edit_service.py @@ -457,7 +457,7 @@ def updateSeries(self, var=None, method=None, qcl=None, is_new_series=False): print("Save existing series ID: %s" % str(series.id)) series = tseries else: - print "Series doesn't exist (if you are not, you should be running SaveAs)" + print("Series doesn't exist (if you are not, you should be running SaveAs)") if is_new_series: diff --git a/odm2api/ODM1_1_1/services/export_service.py b/odm2api/ODM1_1_1/services/export_service.py index 4b6d1eb..ea65498 100644 --- a/odm2api/ODM1_1_1/services/export_service.py +++ b/odm2api/ODM1_1_1/services/export_service.py @@ -19,7 +19,7 @@ def export_series_data(self, series_id, filename, utc=False, site=False, var=Fal return False writer = csv.writer(open(filename, 'wb')) - print "filename: ", filename + print("filename: ", filename) self.write_data_header(writer, utc, site, var, offset, qual, src, qcl) for dv in series.data_values: self.write_data_row(writer, series, dv, utc, site, var, offset, qual, src, qcl) diff --git a/odm2api/ODM1_1_1/services/series_service.py b/odm2api/ODM1_1_1/services/series_service.py index a7ba650..e880831 100644 --- a/odm2api/ODM1_1_1/services/series_service.py +++ b/odm2api/ODM1_1_1/services/series_service.py @@ -286,7 +286,7 @@ def get_series_by_id(self, series_id): try: return self._session.query(ODM.Series).filter_by(id=series_id).first() except Exception as e: - print e + print(e) return None def get_series_by_id_quint(self, site_id, var_id, method_id, source_id, qcl_id): diff --git a/odm2api/ODM2/services/createService.py b/odm2api/ODM2/services/createService.py index f1161c4..1f5309c 100644 --- a/odm2api/ODM2/services/createService.py +++ b/odm2api/ODM2/services/createService.py @@ -262,7 +262,7 @@ def createAffiliation(self, personid, organizationid, email, phone=None, address #self._session.flush() # self._session.refresh(a) - print a.OrganizationID + print(a.OrganizationID) return a @@ -523,8 +523,8 @@ def createTimeSeriesResultValues(self, datavalues): return datavalues - except Exception, e: - print e + except Exception as e: + print(e) return None diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 9a7824e..0628d95 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -331,8 +331,8 @@ def getProcessingLevelByCode(self, processingCode): """ try: return self._session.query(ProcessingLevels).filter_by(ProcessingLevelCode=str(processingCode)).first() - except Exception, e: - print e + except Exception as e: + print(e) return None """ @@ -387,7 +387,7 @@ def getSamplingFeaturesByType(self, samplingFeatureTypeCV): try: return self._session.query(SamplingFeatures).filter_by(SamplingFeatureTypeCV=samplingFeatureTypeCV).all() except Exception as e: - print e + print(e) return None def getSamplingFeatureByGeometry(self, wkt_geometry): @@ -396,17 +396,17 @@ def getSamplingFeatureByGeometry(self, wkt_geometry): # ST_Equals(geometry, geometry) return self._session.query(SamplingFeatures).filter( func.ST_AsText(SamplingFeatures.FeatureGeometry) == func.ST_AsText(wkt_geometry)).first() - except Exception, e: - print e + except Exception as e: + print(e) return None def getGeometryTest(self, TestGeom): Geom = self._session.query(SamplingFeatures).first() - print "Queried Geometry: ", self._session.query(Geom.FeatureGeometry.ST_AsText()).first() + print("Queried Geometry: ", self._session.query(Geom.FeatureGeometry.ST_AsText()).first()) GeomText = self._session.query( func.ST_Union(Geom.FeatureGeometry, func.ST_GeomFromText(TestGeom)).ST_AsText()).first() - print GeomText + print(GeomText) """ Action @@ -773,13 +773,13 @@ def getTimeSeriesResultValuesByResultId(self, resultId): """ try: q = self._session.query(TimeSeriesResultValues).filter_by(ResultID=resultId).all() - print type(q[0]), q[0] + print(type(q[0]), q[0]) df = pd.DataFrame([dv.list_repr() for dv in q]) df.columns = q[0].get_columns() return df # return self._session.query(Timeseriesresultvalue).filter_by(ResultID=resultId).all() except Exception as e: - print e + print(e) return None def getTimeSeriesResultValuesByCode(self, timeSeriesCode): @@ -945,8 +945,8 @@ def getRelatedModelsByID(self, modelid): """ try: return self._session.query(RelatedModels).filter_by(RelatedModelID=modelid).all() - except Exception, e: - print e + except Exception as e: + print(e) return None def getRelatedModelsByCode(self, modelcode): @@ -958,8 +958,8 @@ def getRelatedModelsByCode(self, modelcode): try: return self._session.query(RelatedModels).join(Models, RelatedModels.RelatedModelID == Models.ModelID) \ .filter(Models.ModelCode == modelcode).all() - except Exception, e: - print e + except Exception as e: + print(e) return None def getResultsBySimulationID(self, simulationID): @@ -969,8 +969,8 @@ def getResultsBySimulationID(self, simulationID): .join(Actions) \ .join(Simulations) \ .filter(Simulations.SimulationID == simulationID).all() - except Exception, e: - print e + except Exception as e: + print(e) return None # ################################################################################ diff --git a/odm2api/ODMconnection.py b/odm2api/ODMconnection.py index fa22aa7..410f97b 100644 --- a/odm2api/ODMconnection.py +++ b/odm2api/ODMconnection.py @@ -119,7 +119,7 @@ def testEngine(self, connection_string, echo = False ): s.test_Session().query(Variable2.VariableCode).limit(1).first() except Exception as e: - print "Connection was unsuccessful ", e.message + print("Connection was unsuccessful ", e.message) return False return True @@ -131,7 +131,7 @@ def testEngine1_1(self, connection_string, echo = False ): s.test_Session().query(ODM.Variable.code).limit(1).first() except Exception as e: - print "Connection was unsuccessful ", e.message + print("Connection was unsuccessful ", e.message) return False return True