Skip to content

Commit 0d36ef1

Browse files
author
Miguel Leon
committed
Changes print statments in Examples/Sample.py to make them python 3.x compatible.
1 parent 0077a7b commit 0d36ef1

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

Examples/Sample.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#createconnection (dbtype, servername, dbname, username, password)
2424
#session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')
2525
#session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)
26-
session_factory = dbconnection.createConnection('sqlite', '/Users/denversmith/Downloads/ODM2.sqlite', 2.0)
26+
#session_factory = dbconnection.createConnection('sqlite', '/Users/denversmith/Downloads/ODM2.sqlite', 2.0)
27+
session_factory = dbconnection.createConnection('postgresql', '50.19.46.248:5432', db='postgres',user='postgres',password='RomaeDintorni!m0nel')
2728
# session_factory= dbconnection.createConnection('mssql')
2829

2930

@@ -40,52 +41,52 @@
4041
allVars = read.getVariables()
4142

4243
for x in allVars:
43-
print x.VariableCode + ": " + x.VariableNameCV
44+
print(x.VariableCode + ": " + x.VariableNameCV)
4445

4546

4647

4748
# Get all of the people from the database
4849
allPeople = read.getPeople()
4950

5051
for x in allPeople:
51-
print x.PersonFirstName + " " + x.PersonLastName
52+
print(x.PersonFirstName + " " + x.PersonLastName)
5253

5354
try:
54-
print "\n-------- Information about an Affiliation ---------"
55+
print("\n-------- Information about an Affiliation ---------")
5556
allaff = read.getAllAffiliations()
5657
for x in allaff:
57-
print x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID)
58+
print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID))
5859
except Exception as e:
59-
print "Unable to demo getAllAffiliations", e
60+
print("Unable to demo getAllAffiliations", e)
6061

6162
# Get all of the SamplingFeatures from the database that are Sites
6263
try:
6364
siteFeatures = read.getSamplingFeaturesByType('Site')
6465
numSites = len(siteFeatures)
6566

6667
for x in siteFeatures:
67-
print x.SamplingFeatureCode + ": " + x.SamplingFeatureName
68+
print(x.SamplingFeatureCode + ": " + x.SamplingFeatureName)
6869
except Exception as e:
69-
print "Unable to demo getSamplingFeaturesByType", e
70+
print("Unable to demo getSamplingFeaturesByType", e)
7071

7172

7273
# Now get the SamplingFeature object for a SamplingFeature code
7374
try:
7475
sf = read.getSamplingFeatureByCode('USU-LBR-Mendon')
75-
print sf
76-
print "\n-------- Information about an individual SamplingFeature ---------"
77-
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n"
78-
print "SamplingFeatureCode: " + sf.SamplingFeatureCode
79-
print "SamplingFeatureName: " + sf.SamplingFeatureName
80-
print "SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription
81-
print "SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV
82-
print "SamplingFeatureGeometry: %s" % sf.FeatureGeometry
83-
print "Elevation_m: %s" % str(sf.Elevation_m)
76+
print(sf)
77+
print("\n-------- Information about an individual SamplingFeature ---------")
78+
print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n")
79+
print("SamplingFeatureCode: " + sf.SamplingFeatureCode)
80+
print("SamplingFeatureName: " + sf.SamplingFeatureName)
81+
print("SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription)
82+
print("SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV)
83+
print("SamplingFeatureGeometry: %s" % sf.FeatureGeometry)
84+
print("Elevation_m: %s" % str(sf.Elevation_m))
8485
except Exception as e:
85-
print "Unable to demo getSamplingFeatureByCode: ", e
86+
print("Unable to demo getSamplingFeatureByCode: ", e)
8687

8788
#add sampling feature
88-
print "\n------------ Create Sampling Feature --------- \n",
89+
print("\n------------ Create Sampling Feature --------- \n")
8990
try:
9091
from odm2api.ODM2.models import SamplingFeatures
9192
newsf = SamplingFeatures()
@@ -100,19 +101,19 @@
100101
newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2"
101102
session.add(newsf)
102103
#session.commit()
103-
print "new sampling feature added to database", newsf
104+
print("new sampling feature added to database", newsf)
104105

105106
except Exception as e :
106-
print "error adding a sampling feature: " + str(e)
107+
print("error adding a sampling feature: " + str(e))
107108

108109

109110
# Drill down and get objects linked by foreign keys
110-
print "\n------------ Foreign Key Example --------- \n",
111+
print("\n------------ Foreign Key Example --------- \n",)
111112
try:
112113
# Call getResults, but return only the first result
113114
firstResult = read.getResults()[0]
114-
print "The FeatureAction object for the Result is: ", firstResult.FeatureActionObj
115-
print "The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj
115+
print("The FeatureAction object for the Result is: ", firstResult.FeatureActionObj)
116+
print("The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj)
116117
print ("\nThe following are some of the attributes for the Action that created the Result: \n" +
117118
"ActionTypeCV: " + firstResult.FeatureActionObj.ActionObj.ActionTypeCV + "\n" +
118119
"ActionDescription: " + firstResult.FeatureActionObj.ActionObj.ActionDescription + "\n" +
@@ -121,11 +122,11 @@
121122
"MethodName: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodName + "\n" +
122123
"MethodDescription: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodDescription)
123124
except Exception as e:
124-
print "Unable to demo Foreign Key Example: ", e
125+
print("Unable to demo Foreign Key Example: ", e)
125126

126127

127128
# Now get a particular Result using a ResultID
128-
print "\n------- Example of Retrieving Attributes of a Time Series Result -------"
129+
print("\n------- Example of Retrieving Attributes of a Time Series Result -------")
129130
try:
130131
tsResult = read.getTimeSeriesResultByResultId(1)
131132
print (
@@ -142,19 +143,19 @@
142143
"SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
143144
tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
144145
except Exception as e:
145-
print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e
146+
print("Unable to demo Example of retrieving Attributes of a time Series Result: ", e)
146147

147148
# Get the values for a particular TimeSeriesResult
148-
print "\n-------- Example of Retrieving Time Series Result Values ---------"
149+
print("\n-------- Example of Retrieving Time Series Result Values ---------")
149150

150151
tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe
151152

152153
# Print a few Time Series Values to the console
153154
# tsValues.set_index('ValueDateTime', inplace=True)
154155
try:
155-
print tsValues.head()
156+
print(tsValues.head())
156157
except Exception as e:
157-
print e
158+
print(e)
158159

159160
# Plot the time series
160161

@@ -173,4 +174,4 @@
173174
ax.grid(True)
174175
plt.show()
175176
except Exception as e:
176-
print "Unable to demo plotting of tsValues: ", e
177+
print("Unable to demo plotting of tsValues: ", e)

0 commit comments

Comments
 (0)