def obj_low(self): # In the late afternoon (forecast "Tonight") only the Min temperature is shown low_text = CleanText('./a/dl/dd[1]/b')(self) if low_text: temp = CleanDecimal('./a/dl/dd[1]/b')(self) return Temperature(float(temp), 'C') else: temp = CleanDecimal('./a/dl/dd[1]/strong')(self) return Temperature(float(temp), 'C')
def obj_low(self): temp = CleanDecimal( Regexp(CleanText('./dl/dd/span[@class="min-temp"]'), u'(\d*)\xb0\w Minimale.*'))(self) unit = Regexp(CleanText('./dl/dd/span[@class="min-temp"]'), u'.*\xb0(\w) Minimale.*')(self) return Temperature(float(temp), unit)
def obj_high(self): temp = CleanDecimal( Regexp(CleanText('./dl/dd/span[@class="max-temp"]'), u'(.*)\xb0\w Maximale.*'))(self) unit = Regexp(CleanText('./dl/dd/span[@class="max-temp"]'), u'.*\xb0(\w) Maximale.*')(self) return Temperature(float(temp), unit)
def obj_temp(self): path = u'//table[@class="observation-text"]//span[@class="parameter-name" and text() = "Lämpötila"]' + \ u'/../span[@class="parameter-value"]' temp = CleanDecimal(Regexp(CleanText(path), r'^([^ \xa0]+)'), replace_dots=True)(self) unit = Regexp(CleanText(path), r'\xb0(\w)')(self) return Temperature(float(temp), unit)
def obj_high(self): temp = CleanText('.//span[@class="large-temp"]/text()')(self) # Eliminating the '°' at the end: temp = temp[:-1] unit = CleanText('//span[@class="local-temp"]/text()')(self) unit = unit[-1] return Temperature(float(temp), unit)
def obj_temp(self): temp = CleanDecimal( '//*[@id="current-city-tab"]//span[@class="local-temp"]')(self) unit = Regexp( CleanText( '//*[@id="current-city-tab"]//span[@class="local-temp"]'), u'.*\xb0(\w)')(self) return Temperature(float(temp), unit)
def obj_high(self): temp = Regexp(CleanText('./dl/dd/span[@class="max-temp"]'), u'(.*)\xb0\w Maximale.*')(self) if temp != "-": # Sometimes website does not return high temp = CleanDecimal(temp)(self) unit = Regexp(CleanText('./dl/dd/span[@class="max-temp"]'), u'.*\xb0(\w) Maximale.*')(self) return Temperature(float(temp), unit) return NotAvailable
def obj_high(self): temp = CleanDecimal( Regexp( CleanText('./ul/li[@class="day-summary-temperature"]'), '.* / (.*)'))(self) unit = Regexp( CleanText('./ul/li[@class="day-summary-temperature"]'), u'.* / .*\xb0(\w).*')(self) return Temperature(float(temp), unit)
def obj_temp(self): temp = CleanDecimal( '//div[@id="detail-day-01"]/table/tr[@class="in-between"]/td[1]' )(self) unit = Regexp( CleanText( '//div[@id="detail-day-01"]/table/tr[@class="in-between"]/td[1]' ), u'.*\xb0(\w)')(self) return Temperature(float(temp), unit)
def obj_low(self): temp = Regexp(CleanText('./dl/dd/span[@class="min-temp"]'), u'(\d*)\xb0\w Minimale.*') if temp != "-": # Sometimes website does not return low temp = CleanDecimal(temp)(self) unit = Regexp(CleanText('./dl/dd/span[@class="min-temp"]'), u'.*\xb0(\w) Minimale.*')(self) return Temperature(float(temp), unit) return NotAvailable
def obj_temp(self): temp = CleanDecimal( '//ul[@class="prevision-horaire "]/li[@class=" active "]/ul/li[@class="day-summary-temperature"]' )(self) unit = Regexp( CleanText( '//ul[@class="prevision-horaire "]/li[@class=" active "]/ul/li[@class="day-summary-temperature"]' ), u'.*\xb0(\w)')(self) return Temperature(float(temp), unit)
def obj_low(self): temp = CleanText('.//span[@class="small-temp"]/text()')(self) # For some of the low temperature elements, the value ends with '°', for some others it ends with '°C' or '°F': if temp.endswith('C') or temp.endswith('F'): temp = temp[1:-2] else: temp = temp[1:-1] unit = CleanText('//span[@class="local-temp"]/text()')(self) unit = unit[-1] return Temperature(float(temp), unit)
def obj_high(self): high_temp = CleanText('.//span[@class="large-temp"]')(self) if high_temp: temp = CleanDecimal('.//span[@class="large-temp"]')(self) unit = Regexp( CleanText( '//*[@id="current-city-tab"]//span[@class="local-temp"]' ), u'.*\xb0(\w)')(self) return Temperature(float(temp), unit) return NotAvailable
def obj_temp(self): temp = CleanDecimal( Regexp( CleanText( '(//div[@class="group-days-summary"])[1]/div[1]/div/div/div[@class="day-summary-temperature"]' ), '(.*)\|.*'))(self) unit = Regexp( CleanText( '(//div[@class="group-days-summary"])[1]/div[1]/div/div/div[@class="day-summary-temperature"]' ), u'.*\xb0(\w) \|.*')(self) return Temperature(float(temp), unit)
def obj_low(self): temp = CleanDecimal( Regexp( CleanText( './div/div/div[@class="day-summary-temperature"]'), '(.*)\|.*'))(self) unit = Regexp( CleanText( './div/div/div[@class="day-summary-temperature"]'), u'.*\xb0(\w) \|.*')(self) return Temperature(float(temp), unit)
def get_current(self): obj = Current() obj.id = date.today() obj.date = date.fromtimestamp(self.doc['latestObservationTime'] / 1000) obj.temp = Temperature(max(self.doc['t2m'])[1], u'C') last_hour_precipitations = int(max(self.doc['Precipitation1h'])[1]) nebulosity = int(max(self.doc['TotalCloudCover'])[1]) wind_speed = int(max(self.doc['WindSpeedMS'])[1]) wind_direction = self.WINDS[int( max(self.doc['WindDirection'])[1] / 22.5)] obj.text = u'1h precipitations %d mm, wind %d m/s (%s), nebulosity %d/8' % ( last_hour_precipitations, wind_speed, wind_direction, nebulosity) return obj
def obj_temp(self): #Retrieving the temperature: temp = CleanText( '//div[@id="details"]//span[@class="large-temp"]/text()')(self) #Eliminating the '°' at the end of the temperature value: temp = temp[:-1] temp = CleanDecimal(temp)(self) #Retrieving the temperature unit in Celsius or Fahrenheit: unit = CleanText('//ul[@class="stats"]/li[8]/strong/text()')(self) unit = unit[-1] return Temperature(float(temp), unit)
def obj_temp(self): temp = Dict('vt1observation/temperature')(self) return Temperature(float(temp), 'C')
def obj_high(self): return Temperature(max(self.temperatures()), u'C')
def obj_low(self): return Temperature(min(self.temperatures()), u'C')
def temp(v): t = Temperature() t.unit = 'C' t.value = v return t
def obj_temp(self): temp = CleanDecimal( Dict('query/results/channel/item/condition/temp'))(self) unit = CleanText( Dict('query/results/channel/units/temperature'))(self) return Temperature(float(temp), unit)
def obj_high(self): temp = CleanDecimal(Dict('high'))(self) return Temperature(float(temp), Env('unit')(self))
def obj_temp(self): temp = CleanDecimal('//*[@class="current temp-block"]/span[1]/b')( self) return Temperature(float(temp), 'C')
def obj_high(self): low_text = CleanText('./a/dl/dd[1]/b')(self) if low_text: temp = CleanDecimal('./a/dl/dd[1]/strong')(self) return Temperature(float(temp), 'C')