def daily(): utilities.log( "Fetching Daily Forecast for '%s (%s)' from the Met Office..." % (FORECAST_LOCATION, FORECAST_LOCATION_ID)) with urlcache.URLCache(ADDON_DATA_PATH) as cache: filename = cache.get(DAILY_LOCATION_FORECAST_URL, daily_expiry) data=json.load(open(filename)) try: dv = data['SiteRep']['DV'] dataDate = utilities.strptime(dv.get('dataDate').rstrip('Z'), DATAPOINT_DATETIME_FORMAT).replace(tzinfo=pytz.utc) WINDOW.setProperty('DailyForecast.IssuedAt', dataDate.astimezone(TZ).strftime(ISSUEDAT_FORMAT))#@UndefinedVariable for p, period in enumerate(dv['Location']['Period']): WINDOW.setProperty('Day%d.Title' %p, time.strftime(SHORT_DAY_FORMAT, time.strptime(period.get('value'), DATAPOINT_DATE_FORMAT)))#@UndefinedVariable for rep in period['Rep']: weather_type = rep.get('W', 'na') if rep.get('$') == 'Day': WINDOW.setProperty('Day%d.HighTemp' %p, rep.get('Dm', 'na'))#@UndefinedVariable WINDOW.setProperty('Day%d.HighTempIcon' %p, rep.get('Dm'))#@UndefinedVariable WINDOW.setProperty('Day%d.Outlook' %p, WEATHER_CODES.get(weather_type)[1])#@UndefinedVariable WINDOW.setProperty('Day%d.OutlookIcon' % p, WEATHER_ICON_PATH % WEATHER_CODES.get(weather_type, 'na')[0])#@UndefinedVariable WINDOW.setProperty('Day%d.WindSpeed' % p, rep.get('S', 'na'))#@UndefinedVariable WINDOW.setProperty('Day%d.WindDirection' % p, rep.get('D', 'na').lower())#@UndefinedVariable elif rep.get('$') == 'Night': WINDOW.setProperty('Day%d.LowTemp' %p, rep.get('Nm', 'na'))#@UndefinedVariable WINDOW.setProperty('Day%d.LowTempIcon' %p, rep.get('Nm'))#@UndefinedVariable except KeyError as e: e.args = ("Key Error in JSON File", "Key '{0}' not found while processing file from url:".format(e.args[0]), DAILY_LOCATION_FORECAST_URL) raise WINDOW.setProperty('DailyForecast.IsFetched', 'true')#@UndefinedVariable
def threehourly(): utilities.log( "Fetching 3 Hourly Forecast for '%s (%s)' from the Met Office..." % (FORECAST_LOCATION, FORECAST_LOCATION_ID)) with urlcache.URLCache(ADDON_DATA_PATH) as cache: filename = cache.get(THREEHOURLY_LOCATION_FORECAST_URL, threehourly_expiry) data=json.load(open(filename)) try: dv = data['SiteRep']['DV'] dataDate = utilities.strptime(dv.get('dataDate').rstrip('Z'), DATAPOINT_DATETIME_FORMAT).replace(tzinfo=pytz.utc) WINDOW.setProperty('3HourlyForecast.IssuedAt', dataDate.astimezone(TZ).strftime(ISSUEDAT_FORMAT))#@UndefinedVariable count = 1 for period in dv['Location']['Period']: for rep in period['Rep']: #extra xbmc targeted info: weather_type = rep.get('W', 'na') WINDOW.setProperty('Hourly.%d.Outlook' % count, WEATHER_CODES.get(weather_type)[1])#@UndefinedVariable WINDOW.setProperty('Hourly.%d.WindSpeed' % count, rep.get('S', 'n/a'))#@UndefinedVariable WINDOW.setProperty('Hourly.%d.WindDirection' % count, rep.get('D', 'na').lower())#@UndefinedVariable WINDOW.setProperty('Hourly.%d.GustSpeed' % count, rep.get('G', 'n/a'))#@UndefinedVariable WINDOW.setProperty('Hourly.%d.UVIndex' % count, rep.get('U', 'n/a'))#@UndefinedVariable WINDOW.setProperty('Hourly.%d.Precipitation' % count, rep.get('Pp') + "%")#@UndefinedVariable WINDOW.setProperty('Hourly.%d.OutlookIcon' % count, "%s.png" % WEATHER_CODES.get(weather_type, 'na')[0])#@UndefinedVariable WINDOW.setProperty('Hourly.%d.ShortDate' % count, time.strftime(SHORT_DATE_FORMAT, time.strptime(period.get('value'), DATAPOINT_DATE_FORMAT)))#@UndefinedVariable WINDOW.setProperty('Hourly.%d.Time' % count, utilities.minutes_as_time(int(rep.get('$'))))#@UndefinedVariable WINDOW.setProperty('Hourly.%d.Temperature' % count, utilities.rownd(utilities.localised_temperature(rep.get('T', 'na')))+TEMPERATUREUNITS)#@UndefinedVariable WINDOW.setProperty('Hourly.%d.ActualTempIcon' % count, rep.get('T', 'na'))#@UndefinedVariable WINDOW.setProperty('Hourly.%d.FeelsLikeTemp' % count, utilities.rownd(utilities.localised_temperature(rep.get('F', 'na'))))#@UndefinedVariable WINDOW.setProperty('Hourly.%d.FeelsLikeTempIcon' % count, rep.get('F', 'na'))#@UndefinedVariable count +=1 except KeyError as e: e.args = ("Key Error in JSON File", "Key '{0}' not found while processing file from url:".format(e.args[0]), THREEHOURLY_LOCATION_FORECAST_URL) raise WINDOW.setProperty('Hourly.IsFetched', 'true')#@UndefinedVariable
def daily(): utilities.log( "Fetching Daily Forecast for '%s (%s)' from the Met Office..." % (FORECAST_LOCATION, FORECAST_LOCATION_ID)) with urlcache.URLCache(ADDON_DATA_PATH) as cache: filename = cache.get(DAILY_LOCATION_FORECAST_URL, daily_expiry) data = json.load(open(filename)) try: dv = data['SiteRep']['DV'] dataDate = utilities.strptime( dv.get('dataDate').rstrip('Z'), DATAPOINT_DATETIME_FORMAT).replace(tzinfo=pytz.utc) WINDOW.setProperty('DailyForecast.IssuedAt', dataDate.astimezone(TZ).strftime( ISSUEDAT_FORMAT)) #@UndefinedVariable for p, period in enumerate(dv['Location']['Period']): WINDOW.setProperty( 'Day%d.Title' % p, time.strftime( SHORT_DAY_FORMAT, time.strptime(period.get('value'), DATAPOINT_DATE_FORMAT))) #@UndefinedVariable for rep in period['Rep']: weather_type = rep.get('W', 'na') if rep.get('$') == 'Day': WINDOW.setProperty('Day%d.HighTemp' % p, rep.get('Dm', 'na')) #@UndefinedVariable WINDOW.setProperty('Day%d.HighTempIcon' % p, rep.get('Dm')) #@UndefinedVariable WINDOW.setProperty('Day%d.Outlook' % p, WEATHER_CODES.get(weather_type) [1]) #@UndefinedVariable WINDOW.setProperty( 'Day%d.OutlookIcon' % p, WEATHER_ICON_PATH % WEATHER_CODES.get( weather_type, 'na')[0]) #@UndefinedVariable WINDOW.setProperty('Day%d.WindSpeed' % p, rep.get('S', 'na')) #@UndefinedVariable WINDOW.setProperty( 'Day%d.WindDirection' % p, rep.get('D', 'na').lower()) #@UndefinedVariable elif rep.get('$') == 'Night': WINDOW.setProperty('Day%d.LowTemp' % p, rep.get('Nm', 'na')) #@UndefinedVariable WINDOW.setProperty('Day%d.LowTempIcon' % p, rep.get('Nm')) #@UndefinedVariable except KeyError as e: e.args = ("Key Error in JSON File", "Key '{0}' not found while processing file from url:".format( e.args[0]), DAILY_LOCATION_FORECAST_URL) raise WINDOW.setProperty('DailyForecast.IsFetched', 'true') #@UndefinedVariable