Custom Navigation Tiles - How to make a Dynamic Weather Tile using Weather Underground API


#41

my screen shot is as follow.

Yes handler is weather


#42

Looks to be a little cool in Bristol…


##WeatherModule [weather] (Script)##

Script Name: WeatherModule
Script Handler: weather

Script:

var nl = '<linebreak/>';

function current(city,country)
{

  var u = 'http://www.webservicex.net/globalweather.asmx/GetWeather?CityName='+city+'&CountryName='+country;
  //u = 'http://api.openweathermap.org/data/2.5/weather?q='+city+','+country+'&mode=xml';

  var allxml = web.Download(u,'/(.*)/gi');

  // check to see if we got anything from the URL
  var re = /xml/;
  var result = allxml.match(re);
  if (result==null) {
    return 'Weather Not Available.';
  }

  re = /Temperature>\;([^&]+)/;
  result = allxml.match(re);
  var temp = result[1];

  re = /Wind>\;([^&]+)/;
  result = allxml.match(re);
  var wind = result[1].replace(':0','');

  re = /SkyConditions>\;([^&]+)/;
  result = allxml.match(re);
  var sky = result[1];

  return temp + nl + sky + nl + wind;
}

// USAGE
// {CALL:weather.forecast('AR','Newark','your_api_key_here','c')}

function forecast(region,city,key,t)
{
  if (typeof(t) == "undefined") { var t = 'f'; }

  var result = nl;

  var weather = getCurrent(region,city,key)
  result += toBlock(cdegree(weather,t)) + nl;

  var root = getForecast(region,city,key);  
  for (i = 0; i < root.length; i++) {
    result += toBlock(toTile(root[i],t)); 
  }

  return result;
}

function getForecast(region,city,key)
{
  var u = 'http://api.wunderground.com/api/'+key+'/forecast/q/'+region+'/'+city+'.json';
  var allweather = web.Download(u);
  var weather = JSON.parse(allweather);
  return weather.forecast.simpleforecast.forecastday;  
}

function getCurrent(region,city,key)
{
  var u = 'http://api.wunderground.com/api/'+key+'/conditions/q/'+region+'/'+city+'.json';
  var allweather = web.Download(u);
  var weather = JSON.parse(allweather);
  return weather.current_observation;  
}

function toBlock(content)
{
   return '<block 30,0,0,0>' + content + '</block>'
}

function toTile(forecast,t)
{
   return forecast.date.weekday_short + ' ' +sym(forecast.icon) + nl + 
     degree(forecast.high,t) + ' / ' + degree(forecast.low,t);
}

function degree(value, t)
{
   return t=='c' ? value.celsius: value.fahrenheit;
}

function cdegree(value, t)
{
   var result = t=='c' ? value.temp_c: value.temp_f;
   return '<size 70><bold>'+result+' '+degreesym(t)+'</bold></size>';
}

function degreesym(t)
{
   return t=='c' ? 'C�': 'F�';
}

function sym(icon)
{
  if(icon == 'cloudy') return '<sym>?</sym>';
  if(icon == 'rain') return '<sym>?</sym>';
  if(icon == 'snow') return '<sym>?</sym>';
  if(icon == 'partlycloudy') return '<sym>?</sym>';
  if(icon == 'clear') return '<sym>?</sym>';
  return icon;
}



#43

Type this into the Address Bar of a Browser to see what is returned (insert the proper APIKEY, Region, and City) …

http://api.wunderground.com/api/APIKEY/conditions/q/UK/Bristol.json

It should return something like this:


#44

Hmm!! Its still not showing for me. And yes it is quite cold and it looks like its about to rain too!

I like to think I know what im doing here so hitting a blank wall is doing my nut in lol.

Matt


#45

Show us your tile again so we can see the syntax white out your key.


#46

Did you try a manual pull by entering your information into the address bar of a browser to see what is returned? If nothing is returned, maybe your key is bad, mmkay?


#47

He showed a sshot earlier of it working manually. It’s probably a typo somewhere or internet connection


#48

His shot earlier is from browsing the website, not pulling JSON data. It isn’t the same thing.


#49

No I erased his key data but he had it in there. I whited out his key.

EDIT: Ok after reviewing it your right he did. He in fact did not have the info in there. I whited out just the address lol. Sorry Q.


#50

It returned the script you have shown, or like you have shown.

Iternet is on because im using it now on the same PC.

Firewall is switched off.

Just a thought…Am I supposed to be editing the URL in the script?


#51

Thanks

Finally it is showing now but it is showing with Question mark.

Can we set up like this


#52

Question marks has been resolved

can anyone showed me like this


#53

Might be possible to do a tile similar to that but it would require a rewrite of the script as well as a way to capture and display those graphics. We are using built in icons so it’s faster and quicker to display. Using the built in icons also keeps it consistent look


#54

Thanks for your reply.

I have very fast internet connection so downloading will not be an issue. If you need the view source of the page, I can copy for you.

The reason I ask is , It is more Graphical and show more accurate icons


#55

I am really not interested in ripping off sourcecode of another web applet lol. You should look at weatherundergound api and see whats readily available to use legally.


#56

where do you put the script


#57

Manage > Automation > Scripts


#58

do i nee to put anything in the script?


#59

Anybody got a script to get support information to show up on a tile? Like IP, computer name, subnet, gateway… Etc…


#60

I would hazzard a guess you will need to use cmd promp exported to file and read the text file back…

Are these details not fixed though? can you not just set them manually??