Last active
October 25, 2024 15:56
-
-
Save javier/d3ca14497d95109a2d0b21126277c0ee to your computer and use it in GitHub Desktop.
demo_basic_jupyter.ipynb
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
jupyter nbconvert --to webpdf demo_basic_jupyter.ipynb --allow-chromium-download |
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 psycopg as pg | |
import os | |
import matplotlib.pyplot as plt | |
from matplotlib.backends.backend_pdf import PdfPages | |
# Fetch environment variables with defaults | |
host = os.getenv('QDB_CLIENT_HOST', '127.0.0.1') | |
port = os.getenv('QDB_CLIENT_PORT', '8812') | |
user = os.getenv('QDB_CLIENT_USER', 'admin') | |
password = os.getenv('QDB_CLIENT_PASSWORD', 'quest') | |
conn_str = f'user={user} password={password} host={host} port={port} dbname=qdb' | |
with pg.connect(conn_str, autocommit=True) as connection: | |
with connection.cursor() as cur: | |
cur.execute("""\ | |
SELECT | |
rnd_str('EUR','USD', 'GBP', 'BRL','CLP','AUD','EGP','INR', 'KWD', 'JPY') as currency, | |
avg(rnd_double()) as value | |
FROM | |
long_sequence(20,128349234,4327897); | |
""") | |
records = cur.fetchall() | |
plt.figure(figsize=(3, 3)) | |
currency = [record[0] for record in records] | |
value = [record[1] for record in records] | |
plt.bar(currency, value) | |
plt.xlabel('currency') | |
plt.ylabel('value') | |
plt.title('currencies') | |
plt.xticks(rotation=45) | |
plt.plot() | |
pp = PdfPages('report.pdf') | |
pp.savefig() | |
pp.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment