Guest User

Untitled

a guest
Jan 7th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. # -*- coding: utf-8 *-*
  2. """
  3. API, version 0
  4. ~~~~~~~~~~~~~~
  5.  
  6. Basic API object, implements core functions that should not be replaced in any child classes
  7. """
  8. from config import *
  9. import psycopg2
  10.  
  11. class API(object):
  12. """API, version 0 (core)"""
  13. version = 0
  14. PgDB = None
  15.  
  16. def __init__(self):
  17. super(API, self).__init__()
  18.  
  19. def get_version (self, request):
  20. """ Get current API version
  21.  
  22. :Returns:
  23. api version number, integer
  24. """
  25. return self.version
  26.  
  27. def get_server_time (self, request):
  28. """ Get current time on API server
  29.  
  30. :Returns:
  31. date and time in format 2012-08-26 16:20:07, string
  32. """
  33. import datetime
  34. return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  35.  
  36. def get_random_uuid (self, request):
  37. """ Generate random UUID
  38.  
  39. :Returns:
  40. random UUID, string
  41. """
  42. from uuid import uuid4
  43. return str(uuid4())
  44.  
  45. def __initDB(self):
  46. """ Initialize PostgreSQL connection """
  47. self.PgDB = psycopg2.connect(host=CONF_DB_HOST, database=CONF_DB_NAME, user=CONF_DB_USER, password=CONF_DB_PASSWORD)
  48.  
  49. def __del__(self):
  50. if not self.PgDB == None and self.PgDB.closed == 0:
  51. self.PgDB.close()
Add Comment
Please, Sign In to add comment