Tag Archive for 'php'

Building a weather service

Create web service to return personal weather station or airport weather station data from wunderground.com.

The web service will return JSON or XML data. wunderground.com API returns XML data.

When a user request weather information for a location, the web service will return the closest weather information for that location that is available. If nothing is available, or the closest is deemed to be too far away, the user will be asked if this is good enuogh and a message will be added to our logs informing the application administrator that closer weather data is required.

If the user, or an administrator adds a new weather station, the longitude and latitude will be added to the database, as with the name of the station, a link, and an ID that will map to a file system location, when it was added and if the last update was successful. Weather stations once added will be updated every 3 hours, 8 times in a 24 hour period. These will be translated into JSON files when requested.

The directory system will be based on weather station ID and the date in the form YYYYMMDD. Each directory will only contain up to 8 XML files, relating to a single weather station and day. Each directory may also contain JSON files. Perhaps a PHP XSLT engine, or C XSLT engine could be used to generate the desired JSON and JSONP files. We may utilise a library such as Xalan-C to generate JSON files. I’ve investigated XSLT solutions and it appears that PHP has suitable XSLT functions. I will modify this procedure, but it shows that the functionality is suitable.

$proc = new XSLTProcessor();

if (!$proc->hasExsltSupport())
{
   die('EXSLT support not available');
}
// Load the XML source
$xml = new DOMDocument;
$xml->load('test.xml');

$xsl = new DOMDocument;
$xsl->load('test.xsl');

// Configure the transformer
$proc->importStyleSheet($xsl); // attach the xsl rules

if(isset($_GET["callback"])) echo $_GET["callback"]."(";
echo $proc->transformToDoc($xml)->firstChild->wholeText;
if(isset($_GET["callback"])) echo ")";

We will be able to resolve the closest weather station or stations to a particular point and (in our user interface) allow a user to select the favoured weather station.

London based developer for hire… almost

I’m just going through the process of creating and updating my CV for the UK market; I’ll be alive and kicking in London on the 17th of April with a Visa valid for work until March 2012.

I am expecting the market will be difficult; based on the news provided by the BBC and reports from friends in London and the United Kingdom. But I am excited about getting to London and looking for work as a software developer.

I would quite like to get my teeth into a role where I can implement a lot of the areas I have been working on recently and form aspects I consider ideal in a web application solution; specifically:

  • xhtml web pages should be easy to parse, quick to load and forward compatible with future developments in html standards.
  • unobtrusive javascript because the tools that you choose should embrace users, not restrict them.
  • microformats to simplify post-processing of content
  • SOAP/ RESTful webservices to provide opportunities for developers and organisations to extend application functionality.
  • Java (or PHP, or C) because that’s what I do!
  • Subversion makes sense and is easy to use, like CVS
  • Linux, though I usually get Windows at work, I’d like to work on OSX, BSD or Linux instead; it is what we used at Uni.

Really I’m not particularly picky about projects I pick up; as my CV shows, I have taken on a diverse range of projects and change is good.

I have just uploaded my Java 2 developer certification project and now purchasing my developer certification essay. Hopefully I will have Java developer certification by the time I am looking for work in London.

I have also uploaded my “CV” with 1st contact. They recommend using their online tool; which was quite painful, so I ended up only entering some of my work experience. I’d probably just upload my offline CV given hindsight. They say don’t share your CV around with anyone else and so did the next website I went to, so I decided I’d stay faithful to 1st contact and wait till I got to the UK to spread the love.

K2 & Wordpress upgrade to 2.7.1

I had a couple of small problems upgrading to 2.7.1.

Firstly, I am using automatic upgrade (which is usually magic) and it encountered an error with a function being previously defined. So I had to do a manual upgrade, which doesn’t appear anywhere near as professional.

After the manual upgrade, I had a problem with the appearance of this blog. Looking at the output HTML I discovered an error was drawn into the class attribute of the body element. The function join was being called with the wrong parameters. After some googling and grep searches for information about which functions are part of the PHP and Wordpress APIs, it appears that the functionality of the Wordpress function attribute_escape or the hook body_class doesn’t exist anymore.

To fix (though I imagine I’ll need to address this next time I upgrade) I edited function k2_body_class in k2/app/include/info.php so the attribute_join is called with the output of join as the argument, not vice versa as it was previously:

   $c = attribute_escape( join( " ", apply_filters('body_class', $c) ) );

Perhaps an upgrade of K2 is a better idea?