Guest User

Untitled

a guest
Jan 4th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. class statlogging():
  2.     db = None
  3.     cur = None
  4.  
  5.     def connect(self):
  6.         self.db = pg2.connect (database="statslog", user="society", password="1234")
  7.         logger.info("Connected to statslogging db!")
  8.         return self.db
  9.        
  10.     def log(self, name=None, ip='', action='', extra=''):
  11.         if self.db == None:
  12.             self.db = self.connect()
  13.         self.cur = self.db.cursor()
  14.         query = """INSERT INTO stats (date, ip, action, extra)
  15.                    VALUES ('%s', '%s', '%s', '%s');""" % ( datetime.now(), ip, action, extra)
  16.         self.cur.execute(query)
  17.         self.db.commit ()
  18.         logger.info(query)
  19.  
  20.     def close(self):
  21.         self.cur.close()
  22.         self.db.close()
Add Comment
Please, Sign In to add comment