Exemple #1
0
 def __init__(self):
     ProbeParser.__init__(self)
     # the HTML parser info
     self.__html_parser = AragonaireHTMLParser()
     
     # fill up the probe list. 
     #
     self.probe_list.append(
         Probe(u'Alagón', ARAGONAIRE_ES_PROBE_ALAGON_URL, 
             ARAGONAIRE_ES_PROBE_ALAGON_LAT, ARAGONAIRE_ES_PROBE_ALAGON_LON))
     self.probe_list.append(
         Probe(u'Bujaraloz', ARAGONAIRE_ES_PROBE_BUJARALOZ_URL, 
             ARAGONAIRE_ES_PROBE_BUJARALOZ_LAT, ARAGONAIRE_ES_PROBE_BUJARALOZ_LON))
     self.probe_list.append(
         Probe(u'Huesca', ARAGONAIRE_ES_PROBE_HUESCA_URL, 
             ARAGONAIRE_ES_PROBE_HUESCA_LAT, ARAGONAIRE_ES_PROBE_HUESCA_LON))
     self.probe_list.append(
         Probe(u'Monzón', ARAGONAIRE_ES_PROBE_MONZON_URL, 
             ARAGONAIRE_ES_PROBE_MONZON_LAT, ARAGONAIRE_ES_PROBE_MONZON_LON))
     self.probe_list.append(
         Probe(u'Teruel', ARAGONAIRE_ES_PROBE_TERUEL_URL, 
             ARAGONAIRE_ES_PROBE_TERUEL_LAT, ARAGONAIRE_ES_PROBE_TERUEL_LON))
     self.probe_list.append(
         Probe(u'Torrelisa', ARAGONAIRE_ES_PROBE_TORRELISA_URL, 
             ARAGONAIRE_ES_PROBE_TORRELISA_LAT, ARAGONAIRE_ES_PROBE_TORRELISA_LON))
Exemple #2
0
class AragonaireDotEsLiveProbeParser(ProbeParser):
    """
        Parser to retrieve probe data from aragonaire.es
        
        Each probe has a specific data URL which will be used
        to download the HTML content and parse the live probe feed
    """
    
    def __init__(self):
        ProbeParser.__init__(self)
        # the HTML parser info
        self.__html_parser = AragonaireHTMLParser()
        
        # fill up the probe list. 
        #
        self.probe_list.append(
            Probe(u'Alagón', ARAGONAIRE_ES_PROBE_ALAGON_URL, 
                ARAGONAIRE_ES_PROBE_ALAGON_LAT, ARAGONAIRE_ES_PROBE_ALAGON_LON))
        self.probe_list.append(
            Probe(u'Bujaraloz', ARAGONAIRE_ES_PROBE_BUJARALOZ_URL, 
                ARAGONAIRE_ES_PROBE_BUJARALOZ_LAT, ARAGONAIRE_ES_PROBE_BUJARALOZ_LON))
        self.probe_list.append(
            Probe(u'Huesca', ARAGONAIRE_ES_PROBE_HUESCA_URL, 
                ARAGONAIRE_ES_PROBE_HUESCA_LAT, ARAGONAIRE_ES_PROBE_HUESCA_LON))
        self.probe_list.append(
            Probe(u'Monzón', ARAGONAIRE_ES_PROBE_MONZON_URL, 
                ARAGONAIRE_ES_PROBE_MONZON_LAT, ARAGONAIRE_ES_PROBE_MONZON_LON))
        self.probe_list.append(
            Probe(u'Teruel', ARAGONAIRE_ES_PROBE_TERUEL_URL, 
                ARAGONAIRE_ES_PROBE_TERUEL_LAT, ARAGONAIRE_ES_PROBE_TERUEL_LON))
        self.probe_list.append(
            Probe(u'Torrelisa', ARAGONAIRE_ES_PROBE_TORRELISA_URL, 
                ARAGONAIRE_ES_PROBE_TORRELISA_LAT, ARAGONAIRE_ES_PROBE_TORRELISA_LON))

    def update(self):
        for thisProbe in self.probe_list:
            print "parsing aragonaire.es - " + thisProbe.name + "..."
            # ensure the aprser is clean to start the parsing process
            self.__html_parser.reset()

            req = urllib2.Request(thisProbe.dataURL, data=None, headers=HTTP_HEADERS)
            htmlFile = urllib2.urlopen(req)
        
            # charset detection fails in airecantabria.com
            #charset = htmlFile.headers.getparam('charset')

            for line in htmlFile.readlines():
                # aragonaire is UTF-8  
                line = line.strip()

                try:
                    self.__html_parser.feed(line)
                except HTMLParseError, ex:
                    print "Exception %s" % (ex.msg)

            htmlFile.close()
            
            thisMeasure = ProbeMeasure()
            thisMeasure.sample_time = self.__html_parser.m_sampleTime

            if ('CO' in self.__html_parser.m_pollutants):
                thisMeasure.co = self.__html_parser.m_pollutants['CO']
            if ('NO2' in self.__html_parser.m_pollutants):
                thisMeasure.no2 = self.__html_parser.m_pollutants['NO2']
            if ('SO2' in self.__html_parser.m_pollutants):
                thisMeasure.so2 = self.__html_parser.m_pollutants['SO2']
            if ('O3' in self.__html_parser.m_pollutants):
                thisMeasure.o3 = self.__html_parser.m_pollutants['O3']
            
            # update probe's latest measure reference
            thisProbe.last_measure = thisMeasure