0

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!

Aaron Nelson
  • 181
  • 14
  • 2
    Looks like you're calling `put_object` twice in each of those `if` and `elif` blocks. What happens if you comment out each second line? The ones that begin with `graph.put_object(`. – Kevin Jun 05 '17 at 13:07
  • geeze what a bone-head I am! Yep that worked. I don't know why I missed that since I've reviewed it a thousand times it seems. Just neded a fresh set of eyes I guess. Thanks Kevin! – Aaron Nelson Jun 05 '17 at 13:15

0 Answers0