Created
April 14, 2018 22:42
-
-
Save emresaglam/d1e03f6c9ed0d59b2654b2a6ade31c4e to your computer and use it in GitHub Desktop.
Script to poll the home assistant database running on PostgreSQL. The only requirement is psycopg2. (The script doesn't do any error/exception handling)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
# The name of the home assistant database | |
DB = "<DBNAME>" | |
# The user to connect to your home assistant database | |
DBUSER = "<DBUSER>" | |
# The IP/hostname of the PostgreSQL server | |
DBHOST = "<DBHOST>" | |
# The password for the user | |
DBPASSWORD = "<DBPASSWORD>" | |
props = "dbname='{}' user='{}' host='{}' password='{}'".format(DB, DBUSER, DBHOST, DBPASSWORD) | |
conn = psycopg2.connect(props) | |
cur = conn.cursor() | |
sizecmd = "select pg_database_size('{}');".format(DB) | |
cur.execute(sizecmd) | |
rows = cur.fetchall() | |
print (rows[0][0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment