Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 *-*
- """
- API, version 0
- ~~~~~~~~~~~~~~
- Basic API object, implements core functions that should not be replaced in any child classes
- """
- from config import *
- import psycopg2
- class API(object):
- """API, version 0 (core)"""
- version = 0
- PgDB = None
- def __init__(self):
- super(API, self).__init__()
- def get_version (self, request):
- """ Get current API version
- :Returns:
- api version number, integer
- """
- return self.version
- def get_server_time (self, request):
- """ Get current time on API server
- :Returns:
- date and time in format 2012-08-26 16:20:07, string
- """
- import datetime
- return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- def get_random_uuid (self, request):
- """ Generate random UUID
- :Returns:
- random UUID, string
- """
- from uuid import uuid4
- return str(uuid4())
- def __initDB(self):
- """ Initialize PostgreSQL connection """
- self.PgDB = psycopg2.connect(host=CONF_DB_HOST, database=CONF_DB_NAME, user=CONF_DB_USER, password=CONF_DB_PASSWORD)
- def __del__(self):
- if not self.PgDB == None and self.PgDB.closed == 0:
- self.PgDB.close()
Add Comment
Please, Sign In to add comment