Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import sys
  2. sys.stdout = sys.stderr
  3.  
  4. import atexit
  5. import threading
  6. import cherrypy
  7.  
  8. from soaplib.wsgi_soap import SimpleWSGISoapApp
  9. from soaplib.service import soapmethod
  10. from soaplib.serializers.primitive import*
  11.  
  12. cherrypy.config.update({'environment': 'embedded'})
  13.  
  14. if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
  15. cherrypy.engine.start(blocking=False)
  16. atexit.register(cherrypy.engine.stop)
  17.  
  18.  
  19. class Root(SimpleWSGISoapApp):
  20. @soapmethod(_returns=String)
  21. def index(self):
  22. """Get the data from the database and return list of rows"""
  23. cursor = self._get_db_handle()
  24.  
  25. sql = """select name, source_comment from public.carpark where public_toilet = %s """ % 'TRUE'
  26. results = []
  27. cursor.execute(sql)
  28. rows=cursor.fetchall()
  29.  
  30. for row in rows:
  31. results.append(str(row))
  32.  
  33. joinedlist = ', '.join(results)
  34. return joinedlist
  35. cursor.close()
  36.  
  37.  
  38. def _get_db_handle(self, host='xxxx.xxxx.com',
  39. dbname='xxxx',user='xxxx',
  40. password='xxxx',mapped=False):
  41. """Get the database handle"""
  42. import psycopg2
  43. from psycopg2 import extras
  44. conn = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'" % (dbname,user,host,password))
  45. if not mapped:
  46. db_handle = conn.cursor()
  47. else:
  48. db_handle = conn.cursor(cursor_factory=extras.DictCursor)
  49. return db_handle
  50.  
  51. index.exposed = True
  52.  
  53. application = cherrypy.Application(Root(), script_name=None, config=None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement