Python脚本向Facebook发布两次而不是一次

时间:2017-06-05 13:05:40

标签: python class multiple-results

我编写了一个Python脚本,当超过河流水平时会向我的Facebook页面发布警告。我注意到,当它发布到Facebook时它会这样做两次。一旦有数据,第二次没有数据。我无法弄清楚它导致第二篇文章的位置。以下是代码的Class部分:

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())

类对象上面的代码都是html解析和列表构建,所以为了简洁起见,我没有将它包含在示例中。如果我需要包括它,我会这样做。谢谢你的帮助!

0 个答案:

没有答案