def write_everything_from_yahoo_to_xml(country, cities, outfile='weather.xml'): """ Write all the results from google to an xml file """ weather_reports = pywapi.get_everything_from_yahoo(country, cities) xml_output = Element('Weather') for city, report in weather_reports.items(): try: xml_city = Element('town') xml_name = Element('name') xml_name.text = city xml_city.append(xml_name) xml_temperature = Element('temperature') temp_c = report['wind']['chill'] temp_unit = report['units']['temperature'] temp_cond = ''.join([temp_c, ' ', temp_unit]) xml_temperature.text = temp_cond xml_city.append(xml_temperature) xml_humidity = Element('humidity') xml_humidity.text = report['atmosphere']['humidity'] xml_city.append(xml_humidity) xml_condition = Element('condition') xml_condition.text = report['condition']['text'] xml_city.append(xml_condition) xml_wind = Element('wind') beaufort = pywapi.wind_beaufort_scale(report['wind']['speed']) direction = pywapi.wind_direction(report['wind']['direction']) wind_cond = ''.join([beaufort, ' ', direction]) xml_wind.text = wind_cond xml_city.append(xml_wind) xml_output.append(xml_city) except KeyError: pass ElementTree(xml_output).write(outfile, 'UTF-8')
def write_everything_from_yahoo_to_xml(country, cities, outfile='weather.xml'): """ Write all the results from google to an xml file """ weather_reports = pywapi.get_everything_from_yahoo(country, cities) xml_output = Element('Weather') for city, report in weather_reports.items(): try: xml_city = Element('town') xml_name = Element('name') xml_name.text = city xml_city.append(xml_name) xml_temperature = Element('temperature') temp_c = report['wind']['chill'] temp_unit = report['units']['temperature'] temp_cond = ''.join([temp_c, ' ', temp_unit]) xml_temperature.text = temp_cond xml_city.append(xml_temperature) xml_humidity = Element('humidity') xml_humidity.text = report['atmosphere']['humidity'] xml_city.append(xml_humidity) xml_condition = Element('condition') xml_condition.text = report['condition']['text'] xml_city.append(xml_condition) xml_wind = Element('wind') beaufort = pywapi.wind_beaufort_scale(report['wind']['speed']) direction = pywapi.wind_direction(report['wind']['direction']) wind_cond = ''.join([beaufort, ' ', direction]) xml_wind.text = wind_cond xml_city.append(xml_wind) xml_output.append(xml_city) except KeyError: pass ElementTree(xml_output).write(outfile, 'UTF-8')
'TMP': cur_cond['temperature'] + '°', 'HUM': cur_cond['humidity'] + '%', 'FLK': cur_cond['feels_like'] + '°', 'TXT': cur_cond['text'].lower().replace(' ', ''), 'BAR': cur_cond['barometer']['reading'] + units['pressure'], 'DEW': cur_cond['dewpoint'] + '°' + units['temperature'], 'WND': (wind['speed'] + ' ' + units['speed'] + ' from ' + wind['text']) if wind['speed'] != 'calm' else wind['text'], 'BEU': pywapi.wind_beaufort_scale(wind['speed']), 'CPR': forcast[0]['day']['chance_precip'] + '%' } wtr['ICO'] = icons_path + wtr['TXT'] + '.png' for elements in forcast: days.append(elements['day_of_week'].upper()[:2]) high.append(elements['high'] + '°') lows.append(elements['low']) cond.append(os.environ['HOME'] + conky_loc + '/weather_icons/day/' + elements['day']['text'].lower().replace(' ', '') + '.png') cond[0] = os.environ['HOME'] + conky_loc + '/weather_icons/day/' + wtr[ 'TXT'] + '.png' forecasts_ready.update({
+ ' -p ' + str(posx) \ + ',' + str(posy) \ + ' -s ' + str(sizew) \ + 'x' + str(sizeh) \ + ' -n' + '}' wtr = { 'TMP' : cur_cond['temperature'] + '°', 'HUM' : cur_cond['humidity'] + '%', 'FLK' : cur_cond['feels_like'] + '°', 'TXT' : cur_cond['text'].lower().replace(' ', ''), 'BAR' : cur_cond['barometer']['reading'] + 'mb', 'DEW' : cur_cond['dewpoint'] + '°C', 'WND' : (wind['speed'] + ' km/h from ' + wind['text']) if wind['speed'] != 'calm' else wind['text'], 'BEU' : pywapi.wind_beaufort_scale(wind['speed']), 'CPR' : forcast[0]['day']['chance_precip'] + '%' } wtr['ICO'] = icons_path + wtr['TXT'] + '.png' for elements in forcast: days.append(elements['day_of_week'].upper()[:2]) high.append(elements['high'] + '°') lows.append(elements['low']) cond.append(os.environ['HOME'] + '/.conky/weather/weather_icons/day/' + elements['day']['text'].lower().replace(' ', '') + '.png') cond[0] = os.environ['HOME'] + '/.conky/weather/weather_icons/day/' + wtr['TXT'] + '.png' forecasts_ready.update({'days': days, 'highs': high, 'lows': lows, 'cond': cond})