Guest User

Untitled

a guest
Feb 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import psycopg2
  2. import psycopg2.extras
  3.  
  4. class Database:
  5. variable = "blah"
  6.  
  7. def getAccount(self):
  8. accountId = 0;
  9. username = ""
  10. password = ""
  11. try:
  12. conn = psycopg2.connect("dbname='token_generator' user='token_generator' host='myip' password='mypass'")
  13. cur = conn.cursor()
  14. try:
  15. cur.execute("""SELECT id, username, password from account where used = false limit 1""")
  16. except Exception as e: print(e)
  17. rows = cur.fetchall()
  18. for row in rows:
  19. accountId = row[0]
  20. username = row[1]
  21. password = row[2]
  22. except:
  23. print("I am unable to connect to the database")
  24. return (accountId, username, password)
  25.  
  26.  
  27. def insertToken(self, token, accountId):
  28. try:
  29. conn = psycopg2.connect("dbname='token_generator' user='token_generator' host='myip' password='mypass'")
  30. cur = conn.cursor()
  31. try:
  32. cur.execute("INSERT INTO token (token, account_id) VALUES (%s, %s)", (token, accountId))
  33. except Exception as e: print(e)
  34. except:
  35. print("I am unable to connect to the database")
Add Comment
Please, Sign In to add comment