I wrote a Python script that posts a warning to my Facebook Page when the river levels have been exceeded. I've noticed that when it posts to Facebook it does so twice. Once with the data, and the second time with no data. I can't figure out where it is causing the second post. Here is the Class
portion of the code:
class River():
def __init__(self, station, stage, major, moderate, flood, action, warn):
self.station = station
self.stage = stage
self.major = major
self.moderate = moderate
self.flood = flood
self.action = action
self.warn = warn
if self.major == 0:
self.major = self.action
if self.moderate == 0:
self.moderate = self.action
if self.flood == 0:
self.flood = self.action
def alerts(self):
if float(self.stage) < float(self.action):
pass
elif float(self.stage) >= float(self.major):
warn = ('The %s has reached [Major Flood Stage: (%sFt)] @ %sFt.\n\n Warnings: \n%s\n\nPlease click the Link below for more information.' % (self.station, self.major, self.stage, self.warn)), link = river_url)
graph.put_object(parent_object='me', connection_name='feed', message = warn, link = river_url)
elif float(self.stage) >= float(self.moderate):
warn = ('The %s has reached [Moderate Flood Stage: (%sFt)] @ %sFt.\n \n Warnings: \n%s\n\nPlease click the Link below for more information.' % (self.station, self.moderate, self.stage, self.warn)), link = river_url)
graph.put_object(parent_object='me', connection_name='feed', message = warn, link = river_url)
elif float(self.stage) >= float(self.flood):
warn = ('The %s has reached [Flood Stage: (%sFt)] @ %sFt.\n\n Warnings: \n%s\n\nPlease click the Link below for more information.' % (self.station, self.flood, self.stage, self.warn)), link = river_url)
graph.put_object(parent_object='me', connection_name='feed', message = warn, link = river_url)
elif float(self.stage) >= float(self.action):
warn = ('The %s has reached [Action Flood Stage: (%sFt)] @ %sFt.\n\n Warnings: \n%s\n\nPlease click the Link below for more information.' % (self.station, self.action, self.stage, self.warn)), link = river_url)
graph.put_object(parent_object='me', connection_name='feed', message = warn, link = river_url)
def riverlist():
river_list = []
for n in range(len(stx_list)):
station = River(stx_list[n], levels[n], major_lvl[n], moderate_lvl[n], flood_lvl[n], action_lvl[n], warns[n])
river_list.append(station)
return river_list
if __name__ == '__main__':
for river in riverlist():
print(river.alerts())
The code above the Class object is all html parsing and list building so I did not include it in the sample for the sake of brevity. If I need to include it I will do so. Thanks for the help!