You are here: TUTWiki>Wille>Examples (revision 15)
This document is valid for Wille's development version.

Examples

All examples are available under Wille's Basic Bundle, in examples profile. You can also add individual example services to your Wille installation, by creating a new directory for each service under Wille's services folder.

TBD: more examples from core?

@@@

Weather Report Service

Weather Report (weather) is a service that generates a seven-day weather report for a given location by utilising public web APIs.

The service demonstrates the use of Wille for following purposes:

  • Calling a HTTP-based web API (Google Maps Geocoding Service)
  • Generation of a Web Services client from WSDL and calling a service from the client (National Weather Service Web Services API)

The service uses the following Python libraries:

Implementation (weather.py)

import wille

class WeatherService(wille.Service):
	def execute(self, params, servicepool, keyring, workdir):
		# Parse end urlencode input parameter(s)
		from urllib import quote
		e_address = quote(params['address'])

		# Define to get a seven day weather report, starting from today
		from datetime import datetime, timedelta
		starttime = datetime.today().strftime("%Y-%m-%d")
		endtime = (datetime.today()+timedelta(days=7)).strftime("%Y-%m-%d")
		
		# Geocode address
		import httplib2
		import simplejson as json
		geocoder_root_url = 'http://maps.google.com/maps/api/geocode/json?'
		geocoder_req_url = geocoder_root_url+'address='+e_address+'&sensor=false'
		h = httplib2.Http("")
		resp, content = h.request(geocoder_req_url)
		geocoder_result = json.loads(content)
		location = geocoder_result['results'][0]['geometry']['location']
		
		# Get a day weather report
		from suds.client import Client
		forecast_wsdl_url = 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl'
		client = Client(forecast_wsdl_url)
		weather_report = client.service.NDFDgen(latitude = location['lat'], \
											    longitude = location['lng'], \
											    product = 'time-series', \
											    startTime = starttime, \
											    endTime = endtime, \
											    weatherParameters = False )
		
		# Return weather report XML
		return (weather_report.encode('utf-8'), {'Content-type': 'application/xml; charset=utf-8'})

Service Wrapper (willeservice.properties)

description=Exemplary weather report generator service
parameters=address
profile=examples
adapter=PythonService
adapter.command=weather.WeatherService}}}
Print version |  PDF  | History: r19 | r16 < r15 < r14 < r13 | 
Topic revision: r15 - 28 Apr 2010 - 15:53:26 - JaakkoSalonen
 

TUTWiki

Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TUTWiki? Send feedback