Skip to content

Instantly share code, notes, and snippets.

@booyaa
Created April 25, 2011 16:54
Show Gist options
  • Save booyaa/940802 to your computer and use it in GitHub Desktop.
Save booyaa/940802 to your computer and use it in GitHub Desktop.
weather underground xml to pachube eeml
<?php
/*
you need a cron job to grab the correct weather underground xml file.
here's what i use:
*/60 * * * * /usr/bin/curl -o /home/booyaa/public_html/boo/yaa/bay/surbiton.wunder.xml http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=ISURREYS1 >/dev/null 2>&1
*/
$file = "surbiton.wunder.xml";
$xml = simplexml_load_file($file);
$eeml = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<eeml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ee
ml.org/xsd/005" version="5" xsi:schemaLocation="http://www.eeml.org/xsd/005 http
://www.eeml.org/xsd/005/005.xsd">
<environment>
<title>Braggs of Surbiton (Weather Underground)</title>
<description>A weather station in Surbiton</description>
<website>http://booyaa.org/projects/pachube/</website>
<location domain="physical" exposure="outdoor" disposition="fixed">
<name>Braggs of Surbiton (Weather Underground)</name>
<lat>51.390</lat>
<lon>-0.283</lon>
</location>
<data id="0">
<tag>temperature</tag>
<tag>celsius</tag>
<value>$xml->temp_c</value>
<unit symbol="C" type="derivedSI">celsius</unit>
</data>
<data id="1">
<tag>humidity</tag>
<value>$xml->relative_humidity</value>
<unit symbol="%">percentage</unit>
</data>
<data id="2">
<tag>wind</tag>
<tag>direction</tag>
<tag>degree</tag>
<value>$xml->wind_degrees</value>
<unit>degree</unit>
</data>
<data id="3">
<tag>wind</tag>
<tag>speed</tag>
<value>$xml->wind_mph</value>
<unit symbol="mph" type="derivedUnits">miles per hour</unit>
</data>
<data id="4">
<tag>pressure</tag>
<value>$xml->pressure_mb</value>
<unit symbol="mb">barometric pressure</unit>
</data>
<data id="5">
<tag>precipitation</tag>
<value>$xml->precip_1hr_metric</value>
<unit symbol="mm" type="derivedUnits">millimetre</unit>
</data>
</environment>
</eeml>
END;
header("Content-Type: application/xml; charset=utf-8");
print $eeml;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment