Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- sys.stdout = sys.stderr
- import atexit
- import threading
- import cherrypy
- from soaplib.wsgi_soap import SimpleWSGISoapApp
- from soaplib.service import soapmethod
- from soaplib.serializers.primitive import*
- cherrypy.config.update({'environment': 'embedded'})
- if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
- cherrypy.engine.start(blocking=False)
- atexit.register(cherrypy.engine.stop)
- class Root(SimpleWSGISoapApp):
- @soapmethod(_returns=String)
- def index(self):
- """Get the data from the database and return list of rows"""
- cursor = self._get_db_handle()
- sql = """select name, source_comment from public.carpark where public_toilet = %s """ % 'TRUE'
- results = []
- cursor.execute(sql)
- rows=cursor.fetchall()
- for row in rows:
- results.append(str(row))
- joinedlist = ', '.join(results)
- return joinedlist
- cursor.close()
- def _get_db_handle(self, host='xxxx.xxxx.com',
- dbname='xxxx',user='xxxx',
- password='xxxx',mapped=False):
- """Get the database handle"""
- import psycopg2
- from psycopg2 import extras
- conn = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'" % (dbname,user,host,password))
- if not mapped:
- db_handle = conn.cursor()
- else:
- db_handle = conn.cursor(cursor_factory=extras.DictCursor)
- return db_handle
- index.exposed = True
- application = cherrypy.Application(Root(), script_name=None, config=None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement