Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def connect_to_db():
- try:
- #connect to database
- url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
- conn = psycopg2.connect(
- database=url.path[1:],
- user=url.username,
- password=url.password,
- host=url.hostname,
- port=url.port
- )
- print('connected to db\n')
- return [conn, conn.cursor()]
- except Exception as e:
- print("err on connect_db: " + str(e))
- def disconnect_db(conn, cursor):
- try:
- cursor.close()
- conn.close()
- except Exception as e:
- print("err on disconnect_db: " + str(e))
- return False
- return True
- def get_id_from_username(username):
- try:
- [conn, cur] = connect_to_db()
- cur.execute("SELECT chat_id FROM players WHERE username = %s", (username,))
- temp = cur.fetchone()[0]
- disconnect_db(conn, cur)
- return temp
- except Exception as e:
- print("err on get id from username: " + format(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement