Displaying Current Weather Status in SharePoint
OpenWeatherMap.org offers a nice service for obtaining current and forecast weather conditions. Go visit it, and search for the “weather in your city”. In the results page, by hovering the link, you will get the id for the city you are interested in; for example, for “Coimbra, Portugal”, it is 2740637 (http://openweathermap.org/city/2740637).
In a SharePoint page, add a XML Viewer Web Part and point it to the address of the OpenWeatherMap.org web service: http://api.openweathermap.org/data/2.5/weather?id=2740637&mode=xml&units=metric. Of course, do replace the id and also the unit, if you like. Documentation for the web services is available at http://openweathermap.org/api. Next, add the following XSLT transformation:
1: <?xml version="1.0" encoding="UTF-8"?>
2: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3: <xsl:template match="weather">
4: <img>
5: <xsl:attribute name="src">http://openweathermap.org/img/w/<xsl:value-of select="@icon"/>.png</xsl:attribute>
6: <xsl:attribute name="title"><xsl:value-of select="@value"/></xsl:attribute>
7: </img>
8: </xsl:template>
9: <xsl:template match="temperature">
10: <xsl:value-of select="format-number(@value, '#,0')"/>°C
11: </xsl:template>
12: </xsl:stylesheet>
This will add an image for the current status with description and the current temperature. Yes, I could have used a single xsl:template, but I was lazy!
After you save the page, you will get a nice status like this:
I will probably write a post on displaying the forecast. In the meantime, enjoy!