Пример #1
0
    def iter_forecast(self):
        d = date.today()

        self.titles = {}
        for n, tr in enumerate(self.doc.xpath('//table[@id="meteoIntit"]/tr')):
            self.titles[CleanText('.')(tr)] = n

        day_str = None
        for n in range(len(
                self.doc.xpath('//table[@id="meteoHour"]/tr[1]/td'))):
            obj = Forecast()

            t = time(int(self.get_cell(self.titles['Heure'], n).rstrip('h')),
                     0)

            new_day_str = self.get_cell(self.titles['Jour'], n)
            if day_str is not None and day_str != new_day_str:
                d += timedelta(1)
            day_str = new_day_str
            obj.date = datetime.combine(d, t)

            obj.low = obj.high = temp(
                int(
                    self.get_cell(self.titles['T° (ressentie)'],
                                  n).split('°')[0]))
            self.fill_base(obj, n)

            yield obj
Пример #2
0
    def iter_forecast(self):
        d = date.today()

        self.titles = {}
        for n, tr in enumerate(self.doc.xpath('//table[@id="meteo2"]/tr[2]/td[1]/table/tr')):
            self.titles[CleanText('.')(tr)] = n

        for n in range(1, len(self.doc.xpath('//table[@id="meteo2"]/tr[1]/td'))):
            obj = Forecast()
            obj.low = temp(int(self.get_cell(self.titles['Température Mini'], n).rstrip('°')))
            obj.high = temp(int(self.get_cell(self.titles['Température Maxi'], n).rstrip('°')))
            obj.date = d
            self.fill_base(obj, n)

            d += timedelta(1)
            yield obj
Пример #3
0
 def iter_forecast(self):
     forecast = self.doc['vt1dailyForecast']
     for i in range(1, len(forecast['dayOfWeek'])):
         date = parse_date(forecast['validDate'][1])
         tlow = float(forecast['day']['temperature'][i])
         thigh = tlow
         text = forecast['day']['narrative'][i]
         yield Forecast(date, tlow, thigh, text, 'C')
Пример #4
0
 def iter_forecast(self, city_id):
     dom = self._get_weather_dom(city_id)
     for forecast in dom.getElementsByTagName('yweather:forecast'):
         yield Forecast(parse_dt(forecast.getAttribute('date')).date(),
                        float(forecast.getAttribute('low')),
                        float(forecast.getAttribute('high')),
                        unicode(forecast.getAttribute('text')),
                        u'C',
                        )
Пример #5
0
    def iter_forecast(self):
        d = date.today()

        self.titles = {}
        for n, tr in enumerate(self.doc.xpath('//table[@id="meteoIntit"]/tr')):
            self.titles[CleanText('.')(tr)] = n

        day_str = None
        for n in range(len(self.doc.xpath('//table[@id="meteoHour"]/tr[1]/td'))):
            obj = Forecast()

            t = time(int(self.get_cell(self.titles['Heure'], n).rstrip('h')), 0)

            new_day_str = self.get_cell(self.titles['Jour'], n)
            if day_str is not None and day_str != new_day_str:
                d += timedelta(1)
            day_str = new_day_str
            obj.date = datetime.combine(d, t)

            obj.low = obj.high = temp(int(self.get_cell(self.titles['T° (ressentie)'], n).split('°')[0]))
            self.fill_base(obj, n)

            yield obj
Пример #6
0
    def iter_forecast(self):
        for div in self.document.getiterator('li'):
            if div.attrib.get('class', '').startswith('jour'):
                mdate = div.xpath('./dl/dt')[0].text
                t_low = self.get_temp_without_unit(
                    div.xpath('.//dd[@class="minmax"]/strong')[0].text)
                t_high = self.get_temp_without_unit(
                    div.xpath('.//dd[@class="minmax"]/strong')[1].text)
                mtxt = div.xpath('.//dd')[0].text
                yield Forecast(mdate, t_low, t_high, mtxt, 'C')
            elif div.attrib.get('class', '').startswith('lijourle'):
                for em in div.getiterator('em'):
                    templist = em.text_content().split("/")

                    t_low = self.get_temp_without_unit(templist[0])
                    t_high = self.get_temp_without_unit(templist[1])
                    break
                for strong in div.getiterator("strong"):
                    mdate = strong.text_content()
                    break
                for img in div.getiterator("img"):
                    mtxt = img.attrib["title"]
                    break
                yield Forecast(mdate, t_low, t_high, mtxt, "C")
Пример #7
0
    def iter_forecast(self):
        d = date.today() + timedelta(5)

        self.titles = {}
        for n, tr in enumerate(
                self.doc.xpath('(//table[@id="meteo2"]//td/table)[1]/tr/td')):
            self.titles[CleanText('.')(tr)] = n

        cols = len(self.doc.xpath('//table[@id="meteo2"]//td/table'))
        for n in range(1, cols):
            obj = Forecast()
            obj.low = temp(
                int(
                    self.get_cell(self.titles['Température Mini'],
                                  n).rstrip('°C')))
            obj.high = temp(
                int(
                    self.get_cell(self.titles['Température Maxi'],
                                  n).rstrip('°C')))
            obj.date = d
            self.fill_base(obj, n)

            d += timedelta(1)
            yield obj
Пример #8
0
    def iter_forecast(self):
        divs = self.document.findall('//div[@class="wx-daypart"]')

        for day in range (0, len(divs)):
            div = divs[day].find('div[@class="wx-conditions"]')
            text = unicode(div.find('p[@class="wx-phrase"]').text_content().strip())
            try:
                thigh = float(div.find('p[@class="wx-temp"]').text_content().strip().split(u'°')[0])
            except:
                thigh = None
            try:
                tlow = float(div.find('p[@class="wx-temp-alt"]').text_content().strip().split(u'°')[0])
            except:
                tlow = None
            date = divs[day].find('h3/span').text_content().strip()
            #date = self.document.findall('//table[@class="twc-forecast-table twc-first"]//th')[day].text
            #if len (date.split(' ')) > 3:
            #    date = " ".join(date.split(' ', 3)[:3])
            yield Forecast(date, tlow, thigh, text, u'F')