load from config, don't hardcode
This commit is contained in:
parent
f448be8bf8
commit
76f403a6ed
1 changed files with 11 additions and 2 deletions
|
@ -1,9 +1,18 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import yaml
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with sqlite3.connect('/var/lib/knot_rest/database.db') as conn:
|
with open('/etc/knot_rest/knot_rest.yaml') as stream:
|
||||||
|
yamlconf = yaml.safe_load(stream)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
knotrestdb = yamlconf["database"].removeprefix("sqlite:///")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with sqlite3.connect(knotrestdb) as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute('select username, description, logged_in from user')
|
cur.execute('select username, description, logged_in from user')
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
|
@ -14,7 +23,7 @@ try:
|
||||||
description = "(no description)"
|
description = "(no description)"
|
||||||
lastlogin = row[2]
|
lastlogin = row[2]
|
||||||
if lastlogin == None:
|
if lastlogin == None:
|
||||||
lastlogin = "***never logged in***"
|
lastlogin = "**never logged in**"
|
||||||
print(f"{username:<27}{description:<27}{lastlogin:<23}")
|
print(f"{username:<27}{description:<27}{lastlogin:<23}")
|
||||||
except sqlite3.OperationalError as e:
|
except sqlite3.OperationalError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Add table
Reference in a new issue