Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- import psycopg2.extras
- class Database:
- variable = "blah"
- def getAccount(self):
- accountId = 0;
- username = ""
- password = ""
- try:
- conn = psycopg2.connect("dbname='token_generator' user='token_generator' host='myip' password='mypass'")
- cur = conn.cursor()
- try:
- cur.execute("""SELECT id, username, password from account where used = false limit 1""")
- except Exception as e: print(e)
- rows = cur.fetchall()
- for row in rows:
- accountId = row[0]
- username = row[1]
- password = row[2]
- except:
- print("I am unable to connect to the database")
- return (accountId, username, password)
- def insertToken(self, token, accountId):
- try:
- conn = psycopg2.connect("dbname='token_generator' user='token_generator' host='myip' password='mypass'")
- cur = conn.cursor()
- try:
- cur.execute("INSERT INTO token (token, account_id) VALUES (%s, %s)", (token, accountId))
- except Exception as e: print(e)
- except:
- print("I am unable to connect to the database")
Add Comment
Please, Sign In to add comment