I want to use Python to query data out of a MS Database every 5 minutes and post it into a kml to be viewed by multiple people via network link. I get to the end of the code where I am trying to use the if elif to determine which placemark icon is displayed per row result. Here is my sample code:
import simplekml
kml = simplekml.Kml()
pnt = kml.newpoint(name="cpeMAC", coords=[(cpeLON,cpeLAT)])
pnt.description = "FullAddress","Network"
pnt.snippet.content = "cpeMAC","cpeStatus"
pnt.snippet.maxlines = 1
pnt.lookat = simplekml.LookAt(gxaltitudemode=simplekml.GxAltitudeMode.relativetoseafloor,
latitude= cpeLAT, longitude= cpeLON,
range=3000, heading=56, tilt=0)
# The above range, heading and tilt should be hard coded.
# The icon’s for each placemark should change based on the values in cpeStatus. There are 5 output types that can be passed from the dB: None, Off, Repair, Active, Alarm.
# Below is the code that I need the most help with
if cpeStatus = 'Active':
pnt.style.iconstyle.icon.href = "http://maps.google.com/mapfiles/kml/shapes/ranger_station.png"
elif cpeStatus = 'Off':
pnt.style.iconstyle.icon.href = "http://maps.google.com/mapfiles/kml/shapes/forbidden.png"
elif cpeStatus = 'Ready':
pnt.style.iconstyle.icon.href = "http://maps.google.com/mapfiles/kml/shapes/mechanic.png"
elif cpeStatus = 'Alarm':
pnt.style.iconstyle.icon.href = "http://maps.google.com/mapfiles/kml/shapes/caution.png"
return stat
# The file should then be saved to kml stored on the local server.
kml.save("PremiseCPEStatus3.kml")
I am getting the following consistent error:
File "<ipython-input-24-49c8d14fb0c8>", line 26
if cpeStatus = 'Active':
^
SyntaxError: invalid syntax
For reference, the database query is successfully pulling the following information: I separated the rows with a space to make it easier to read
('124-22-A9-12-44-88', 'Alarm', '32.622399444', '-83.60337837', '365 Johns Rd, Warner Robins, GA 31093', 'eCommunity Warner Robins')
('34-E6-AD-E5-AC-77', 'Alarm', '32.621384', '-83.620274', '606 McArthur Blvd, Warner Robins, GA 31093', 'eCommunity Warner Robins')
('36-E6-AD-E5-AC-77', 'Off', '32.623730', '-83.620145', '365 Johns Rd, Warner Robins, GA 3109', 'eCommunity Warner Robins')
('68-F7-28-ED-12-FA', 'Ready', '32.624298', '-83.627544', '112 Anne Dr, Warner Robins, GA 3109', 'eCommunity Warner Robins')
('00-FF-A8-F3-3D-28', 'Active', '32.620851', '-83.630560', '410 Bernard Dr, Warner Robins, GA 3109', 'eCommunity Warner Robins')
(None, None, '32.623577', '-83.628145', '101 Gordon St, Warner Robins, GA 3109', 'eCommunity Warner Robins')
The answer is in the error:
should be:
if cpeStatus == 'Active'
otherwise, you're assigning during an if statement rather than checking its value, invalid syntax.
Also, I'd consider something a little more readable. I would structure it something like this (you don't need to indent since it's all testing the same var)--