Skip to content

Instantly share code, notes, and snippets.

@gamesbook
Created January 10, 2017 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamesbook/3c3ff83f9348a01fff3750f53346db08 to your computer and use it in GitHub Desktop.
Save gamesbook/3c3ff83f9348a01fff3750f53346db08 to your computer and use it in GitHub Desktop.
Simple PyWPS demo for JSON input and output
# -*- coding: utf-8 -*-
"""
Purpose: Demo of basic PyWPS JSON functionality (requires PyWPS v4.0.x)
Created: 10-01-2017
Author: dhohls@csir.co.za
Adapted from:
https://github.com/geopython/pywps-demo/blob/master/demo.py
"""
import json
from pywps import Process, LiteralInput, LiteralOutput, \
ComplexInput, ComplexOutput, Format
class SayGoodbye(Process):
def __init__(self):
inputs = [ComplexInput(
identifier='person',
title='Input details',
data_format=[Format('application/json')])]
outputs = [ComplexOutput(
identifier='response',
title='Output response',
supported_formats=[Format('application/json')])]
super(SayGoodbye, self).__init__(
self._handler,
identifier='say_goodbye',
title='Say Goodbye',
version='1.9.6.3',
inputs=inputs,
outputs=outputs,
store_supported=True,
status_supported=True
)
def _handler(self, request, response):
title = request.inputs['person'][0].data.get('title', 'M.')
firstname = request.inputs['person'][0].data.get('firstname', '')
surname = request.inputs['person'][0].data.get('surname', 'Anonymous')
result = {'greeting':'Goodbye %s %s %' % (title, firstname, surname)}
response.outputs['response'].data = json.dumps(result)
response.outputs['response'].output_format = 'application/json'
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment