Upload
rosamond-bridges
View
215
Download
2
Embed Size (px)
Citation preview
(Another) Assignment Q&A
Appreciating the context … orWhat are we trying to do?
… building an application using external services… or a “service oriented” application
Source : Zdnet
Minimum Requirements / Deliverables (relaxed version)
3 / 4 components depending on group sizeo weather componento news componento a map componento one other (individual)
1 configuration file2 documentation file (xml – structure & schema yet to be published)using any or all of : php, xhtml, xml, kml, rss, css, javascript, yahoo-pipes,csv
BRISTOL / BORDEAUX example
How? crunch rss feeds
Source : yahoo weather rss feeds
Bristol : http://weather.yahooapis.com/forecastrss?p=UKXX0025&u=f
Bordeaux : http://weather.yahooapis.com/forecastrss?p=FRIF0476&u=f
(or use yahoo-pipes)
BRISTOL / BORDEAUX example
example using php & simplexml()
view commented code run code
require_once('utility_lib.php');
$url = 'http://weather.yahooapis.com/forecastrss?p=UKXX0025&u=f';
$rss = @simplexml_load_string(get_file($url));
if($rss) { foreach($rss->channel->item as $item) { echo $item->title.'<br/>'; $ns = $item->children('http://xml.weather.yahoo.com/ns/rss/1.0'); echo (string) $ns->condition->attributes()->text.'<br/>'; echo (string) $ns->condition->attributes()->temp.'°F<br/>'; echo (string) $ns->condition->attributes()->date.'<br/>'; }} else echo "Can't get Bristol Weather Yahoo RSS!";
http://www.webservicex.net/
http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=Bordeaux&CountryName=France
http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=Bristol&CountryName=United Kingdom
example using php & simplexml()
Webservicex REST service: (notoriously unreliable – yahoo weather might be better)
BRISTOL / BORDEAUX example
BRISTOL / BORDEAUX example
<?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://www.webserviceX.NET"> <?xml version="1.0" encoding="utf-16"?> <CurrentWeather> <Location>Bordeaux / Merignac, France (LFBD) 44-50N 000-42W 61M</Location> <Time>Nov 26, 2010 - 04:00 AM EST / 2010.11.26 0900 UTC</Time> <Wind> from the SSW (210 degrees) at 2 MPH (2 KT):0</Wind> <Visibility> greater than 7 mile(s):0</Visibility> <Temperature> 35 F (2 C)</Temperature> <DewPoint> 35 F (2 C)</DewPoint> <RelativeHumidity> 100%</RelativeHumidity> <Pressure> 29.91 in. Hg (1013 hPa)</Pressure> <Status>Success</Status> </CurrentWeather></string> </CurrentWeather></string>
Webservicex REST service response (Bordeaux weather) :
require_once('utility_lib.php');
$url = 'http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=Bordeaux&CountryName=France';
$file = get_file($url);
preg_match('/(<Current.*?<\/CurrentWeather>)/s', $file, $matches);
$xml = simplexml_load_string(html_entity_decode($matches[0]));
echo $xml->Location.'<br/>';echo $xml->Time.'<br/>';echo $xml->Wind.'<br/>';echo $xml->Temperature.'<br/>';
view commented code run code BRISTOL / BORDEAUX example
Process webservicex REST service response (Bordeaux weather) :
Getting and processing news feeds :Sources:Bristol (source: BBC): http://newsrss.bbc.co.uk/rss/local/bristol/front_page/rss.xml
Bordeaux (source: Yahoo News Service):http://news.search.yahoo.com/rss?ei=UTF-8&p=france+bordeaux+news&fr=news-us-ss
BRISTOL / BORDEAUX example
note keywords
$url = 'http://news.search.yahoo.com/rss?ei=UTF-8&p=france+bordeaux+news&fr=news-us-ss';
$rss = @simplexml_load_string(get_file($url), 'SimpleXMLElement', LIBXML_NOCDATA);
if($rss) { foreach($rss->channel->item as $item) { echo '<a href=\''.$item->link.'\'>'.$item->title.'</a><br/>'; }} else echo "Can't get Bristol Weather Yahoo RSS!";
view commented code run code
PHP script to get Bordeaux news:
Google static maps:
http://maps.google.com/maps/api/staticmap
?center=Bordeaux,France&zoom=15&size=800x480&sensor=false
centre of map zoom size size
flickr photos (from public area):
http://www.flickr.com/services/feeds/photos_public.gne
?tags=bristol,cathedral,history&tagmode=all
tags (comma delimited) include all tags
putting it all together:
i) set up a configuration file holding paths, api-keys and other dataview the code for dsa_config.php
ii) build a utility file holding functions and other common codeview the code for dsa_utility.php
iii) build a php a script to bring it all together view the code for index.php
Run the example application here:
http://www.cems.uwe.ac.uk/~p-chatterjee/php/dsa/index.php
registering your group:
- a group registration application will be made available Monday 23rd January on
- you will need to register your group with this application
- the application will assign your group an id
- note that without registration and without a group id – your work cannot be marked!!