more G-Labs products

Author Topic: Weather Underground APP notification flood  (Read 1018 times)

November 01, 2015, 07:13:33 PM
Read 1018 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I have only been using WU since OpenWeatherMap required and API key.  In the past when I used it, there were no notifications.  In the current version, it appears that I have 1 notification for each item extracted from WU and it takes many seconds to finish flooding the notifications.  I could probably add a filter for each one of these, but there are so many it would be tough to click the red button for each of them.  Is there a reason it's displaying so many notifications in the first place?  I don't think anyone wants to see any of them, so can they just be turned off?

November 01, 2015, 08:52:25 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Yes, now it can be disabled thanks to the special Program.UiRefresh event introduced with r499.
All of the Program.RaiseEvents can be now replace with:
Code: [Select]
Program.Parameter("<param>").Value = "<value>";
and just have at the end of the values update:
Code: [Select]
Program.RaiseEvent("Program.UiRefresh", "Data updated", "");

Program.UiRefresh event is a special event to let the widget know that the UI can be refreshed with updated values.
I will include this modification to the app in next release.

This is the updated Program Code (it works with r499 already):
Code: [Select]
var sunsetEvent = "Sunset";
var sunriseEvent = "Sunrise";

while (Program.IsEnabled)
{
  string location = Program.Option("Location").Value;
  string language = Program.Option("Language").Value;
  string apikey = Program.Option("ApiKey").Value;

  // 2014-01-22 - Added to allow user to dyanmically select how to display the temperature. by lancebooth
  string display_celsius = Program.Option("InputDisplayCelsius").Value;

  //
  if (!apikey.Contains("?"))
  {
    try
    {

      string webserviceurl = "http://api.wunderground.com/api/" + apikey + "/geolookup/astronomy/lang:" + language + "/q/" + location + ".json";
      var astronomydata = Net.WebService(webserviceurl).GetData();

      int sunrise_hour = int.Parse(astronomydata.moon_phase.sunrise.hour.ToString());
      int sunrise_minute = int.Parse(astronomydata.moon_phase.sunrise.minute.ToString());
      int sunset_hour = int.Parse(astronomydata.moon_phase.sunset.hour.ToString());
      int sunset_minute = int.Parse(astronomydata.moon_phase.sunset.minute.ToString());

      Program.Parameter("Astronomy.Sunset").Value = sunset_hour.ToString("D2") + ":" + sunset_minute.ToString("D2");
      Program.Parameter("Astronomy.Sunrise").Value = sunrise_hour.ToString("D2") + ":" + sunrise_minute.ToString("D2");

      // Update Scheduler entries
      Scheduler
        .WithName(sunsetEvent)
        .SetSchedule(String.Format("{0} {1} * * *", sunset_minute, sunset_hour));
      Scheduler
        .WithName(sunriseEvent)
        .SetSchedule(String.Format("{0} {1} * * *", sunrise_minute, sunrise_hour));

      webserviceurl = "http://api.wunderground.com/api/" + apikey + "/geolookup/conditions/lang:" + language + "/q/" + location + ".json";
      var weatherdata = Net.WebService(webserviceurl).GetData();

      string city = weatherdata.location.city;
      string country = weatherdata.location.country;
      string country_iso3166 = weatherdata.location.country_iso3166; // eg. IT,US,NL,UK,AU,CH,DE...
      string temperaturec = weatherdata.current_observation.temp_c;
      string temperaturef = weatherdata.current_observation.temp_f;
      string display_location = weatherdata.current_observation.display_location.full;
      string weather_text = weatherdata.current_observation.weather;
      string icon = weatherdata.current_observation.icon;
      string icon_url = weatherdata.current_observation.icon_url.ToString().Replace("c/k", "c/e").Replace("http://icons.wxug", "https://api.wunderground");
      string wind_dir = weatherdata.current_observation.wind_dir;
      string wind_kph = weatherdata.current_observation.wind_kph;
      string pressure_mb = weatherdata.current_observation.pressure_mb;
      string feelslike_c = weatherdata.current_observation.feelslike_c;
      string feelslike_f = weatherdata.current_observation.feelslike_f;
      string UV = weatherdata.current_observation.UV;
      string precip_1hr_metric = weatherdata.current_observation.precip_1hr_metric;

      // 2014-01-22 - Added to allow the widget to display the date/time.
      string last_updated = weatherdata.current_observation.observation_time; //DateTime.Now.ToString("g"); //, new System.Globalization.CultureInfo("en-US")

      Program.Parameter("Conditions.City").Value = city;
      Program.Parameter("Conditions.Country").Value = country;
      Program.Parameter("Conditions.CountryCode").Value = country_iso3166;
      Program.Parameter("Conditions.TemperatureC").Value = temperaturec;
      Program.Parameter("Conditions.TemperatureF").Value = temperaturef;
      Program.Parameter("Conditions.DisplayLocation").Value = display_location;
      Program.Parameter("Conditions.Description").Value = weather_text;
      Program.Parameter("Conditions.IconUrl").Value = icon_url;
      Program.Parameter("Conditions.Status").Value = icon; // eg. cloudy, sunny, etc..
      Program.Parameter("Conditions.WindDirection").Value = wind_dir;
      Program.Parameter("Conditions.WindKph").Value = wind_kph;
      Program.Parameter("Conditions.PressureMb").Value = pressure_mb;
      Program.Parameter("Conditions.FeelsLikeC").Value = feelslike_c;
      Program.Parameter("Conditions.FeelsLikeF").Value = feelslike_f;
      Program.Parameter("Conditions.UV").Value = UV;
      Program.Parameter("Conditions.PrecipitationHourMetric").Value = precip_1hr_metric;

      // 2014-01-22 - Added to allow the widget to display the date/time.
      Program.Parameter("Conditions.LastUpdated").Value = last_updated;

      // 2014-01-22 - Added to allow user to dyanmically select how to display the temperature.
      Program.Parameter("Conditions.DisplayCelsius").Value = display_celsius;

      // 2015-01-30 - Added forecast of next 3 days
      webserviceurl = "http://api.wunderground.com/api/" + apikey + "/forecast/lang:" + language + "/q/" + location + ".json";
      var forecastData = Net.WebService(webserviceurl).GetData().forecast.simpleforecast.forecastday;
      // Collect forecast data
      for (int d = 1; d <= 3; d++)
      {
        Program.Parameter("Conditions.Forecast." + d + ".Description").Value = forecastData[d].conditions.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".Year").Value = forecastData[d].date.year.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".Month").Value = forecastData[d].date.monthname.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".Day").Value = forecastData[d].date.day.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".Weekday").Value = forecastData[d].date.weekday.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".IconUrl").Value = forecastData[d].icon_url.ToString().Replace("c/k", "c/e").Replace("http://icons.wxug", "https://api.wunderground");
        Program.Parameter("Conditions.Forecast." + d + ".TemperatureC.Low").Value = forecastData[d].low.celsius.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".TemperatureF.Low").Value = forecastData[d].low.fahrenheit.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".TemperatureC.High").Value = forecastData[d].high.celsius.ToString();
        Program.Parameter("Conditions.Forecast." + d + ".TemperatureF.High").Value = forecastData[d].high.fahrenheit.ToString();
      }

      Program.RaiseEvent("Program.UiRefresh", "Data Updated", "");
      //Program.Notify("Weather Underground", "Updated.");

    }
    catch (Exception e)
    {

      Program.Notify("Weather Underground ERROR!", "Unable to get data from service. " + e.Message);
      //Program.Parameter("Conditions.City").Value = "ERROR: " + e.Message;
      Console.WriteLine( e.Message );
      Pause(10);

    }
  }
  //
  var delayMins = Program.Option("UpdateInterval").DecimalValue;
  if (delayMins < 1) delayMins = 1;
  var pauseEnd = DateTime.Now.AddMinutes(delayMins);
  var sunEventParameter = Program.Parameter("Sun.Event");
  do
  {
    if (Scheduler.IsScheduling("@Sunrise") && sunEventParameter.Value != sunriseEvent)
    {
      Program.RaiseEvent(sunEventParameter.Name, sunriseEvent, sunriseEvent + " event");
    }
    else if (Scheduler.IsScheduling("@Sunset") && sunEventParameter.Value != sunsetEvent)
    {
      Program.RaiseEvent(sunEventParameter.Name, sunsetEvent, sunsetEvent + " event");
    }
    Pause(1);
  } while (Program.IsEnabled && DateTime.Now.Ticks <= pauseEnd.Ticks);
}

g.
« Last Edit: November 01, 2015, 09:31:15 PM by Gene »

November 02, 2015, 01:35:21 AM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Sounds good.  Thanks for the quick fix.