assignment guidelines, code examples & q&a. appreciating the context … or what are we...
TRANSCRIPT
![Page 1: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/1.jpg)
Assignment Guidelines, Code Examples & Q&A
![Page 2: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/2.jpg)
Appreciating the context … orWhat are we trying to do?
… building an application using external services… or a “service oriented” application
![Page 3: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/3.jpg)
Source : Zdnet
![Page 4: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/4.jpg)
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
![Page 5: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/5.jpg)
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)
![Page 6: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/6.jpg)
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!";
![Page 7: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/7.jpg)
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
![Page 8: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/8.jpg)
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) :
![Page 9: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/9.jpg)
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) :
![Page 10: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/10.jpg)
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:
![Page 11: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/11.jpg)
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
![Page 12: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/12.jpg)
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
![Page 13: Assignment Guidelines, Code Examples & Q&A. Appreciating the context … or What are we trying to do? … building an application using external services](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c623c7/html5/thumbnails/13.jpg)
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!!