Skip to content

Instantly share code, notes, and snippets.

@javier
Last active October 25, 2024 15:56
Show Gist options
  • Save javier/d3ca14497d95109a2d0b21126277c0ee to your computer and use it in GitHub Desktop.
Save javier/d3ca14497d95109a2d0b21126277c0ee to your computer and use it in GitHub Desktop.
demo_basic_jupyter.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 63,
"id": "f8f8d0c5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('BRL', 0.5218652823754089)\n",
"('GBP', 0.5275451357990851)\n",
"('EUR', 0.6203255959451334)\n",
"('INR', 0.278229649849598)\n",
"('KWD', 0.7747921260072678)\n",
"('JPY', 0.6589074527071597)\n",
"('CLP', 0.8100600481532131)\n",
"('AUD', 0.6334735510882324)\n"
]
}
],
"source": [
"import psycopg as pg\n",
"import os\n",
"\n",
"# Fetch environment variables with defaults\n",
"host = os.getenv('QDB_CLIENT_HOST', 'localhost')\n",
"port = os.getenv('QDB_CLIENT_PORT', '8812')\n",
"user = os.getenv('QDB_CLIENT_USER', 'admin')\n",
"password = os.getenv('QDB_CLIENT_PASSWORD', 'quest')\n",
"\n",
"# Create the connection string using the environment variables or defaults\n",
"conn_str = f'user={user} password={password} host={host} port={port} dbname=qdb'\n",
"with pg.connect(conn_str, autocommit=True) as connection:\n",
"\n",
" # Open a cursor to perform database operations\n",
"\n",
" with connection.cursor() as cur:\n",
"\n",
" #Query the database and obtain data as Python objects.\n",
"\n",
" cur.execute(\"\"\"\\\n",
" SELECT \n",
" rnd_str('EUR','USD', 'GBP', 'BRL','CLP','AUD','EGP','INR', 'KWD', 'JPY') as currency, \n",
" avg(rnd_double()) as value \n",
" FROM \n",
" long_sequence(20,128349234,4327897);\n",
" \"\"\")\n",
" records = cur.fetchall()\n",
" for row in records:\n",
" print(row)\n",
"\n",
"# the connection is now closed"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "6d177c9a",
"metadata": {},
"outputs": [
{
"data": {
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DNHARmZoXzcQRmZoVzEJiZFc5BYGZWOAeBmVnhHARmZoVzEJi9CpIGLGvZbGXkILBiSTpE0t2S7pJ0kaQLJe1fuf0f+d/dJf1K0jRgdovl/pLOkDQj39+Rlb+7QdIPJP1B0sVdZ6uUtIOk3+THvk3SEEk3SXpT5fF/nS99aFYr781YkSRtDZwI/HtEPCppfdI55XuyPel893+UtHu35UnAUxGxQz5d882Sfpb/bjvSBc3/TDqd+C6SbiOdu/7AiJghaW3SGWW/DRwKfCKftXJQRNz12v7PzZbmFoGV6m3AFRHxKEAvThN8W7dTaleX9wIOkTSLdFW7DUhXHevabkE+fcQs0gnJtiBd3HxGfuyn8+mdrwDeIWk14MOk6xKY1c4tArMlFpF3jvLFawZWbnum27bVZZEu4XhtdYPccni+suollvGZi4hnJV0HTATeQzqvvVnt3CKwUv0SOEDSBgC5a2geS758J5AuNtIb1wIfzXvySNpc0lrL2H4OsJGkHfL2QyqDzt8CzgFmRMQTr+L/Y7bC3CKwIkXEPZJOA26U9BLpym//CfxY0l2kC8d0bwX05FukLp878mDwQmDfZTz2C5IOBM7NFxx6DtgT+EdE3C7padJlK83awiedM+tDJG0M3ABs6dNSW7u4a8isj5B0CGmw+QSHgLWTWwRmZoVzi8DMrHAOAjOzwjkIzMwK5yAwMyucg8DMrHD/HxygFgFvoWe6AAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"# Separating x and y data\n",
"locotype = [record[0] for record in records]\n",
"code = [record[1] for record in records]\n",
"\n",
"# Plotting the graph\n",
"plt.bar(locotype, code)\n",
"plt.xlabel('currency')\n",
"plt.ylabel('value')\n",
"plt.title('currencies')\n",
"plt.xticks(rotation=45)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7c72457d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.19"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
jupyter nbconvert --to webpdf demo_basic_jupyter.ipynb --allow-chromium-download
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