Merge pull request 'P14: Retrofit 5 notebooks to conf.connect factories' (#80) from feature/notebook-retrofit into main
This commit was merged in pull request #80.
This commit is contained in:
@@ -27,25 +27,16 @@ def _(mo):
|
|||||||
|
|
||||||
@app.cell(hide_code=True)
|
@app.cell(hide_code=True)
|
||||||
def _():
|
def _():
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
_here = Path(__file__).resolve().parent if "__file__" in dir() else Path.cwd()
|
|
||||||
_styles = str((_here / "../styles").resolve())
|
|
||||||
if _styles not in sys.path:
|
|
||||||
sys.path.insert(0, _styles)
|
|
||||||
|
|
||||||
import altair as alt
|
import altair as alt
|
||||||
import duckdb
|
|
||||||
import polars as pl
|
import polars as pl
|
||||||
from nature import PALETTE, altair_theme
|
|
||||||
|
|
||||||
from conf import path as _conf_path
|
from conf import connect
|
||||||
|
|
||||||
altair_theme()
|
connect.theme()
|
||||||
|
|
||||||
DB_PATH = str(_conf_path("db.aco"))
|
from nature import PALETTE # noqa: E402 — needs theme() to add styles to path
|
||||||
con = duckdb.connect(DB_PATH, read_only=True)
|
|
||||||
|
con = connect.duckdb()
|
||||||
|
|
||||||
def q(sql):
|
def q(sql):
|
||||||
"""Run a query and return a Polars DataFrame."""
|
"""Run a query and return a Polars DataFrame."""
|
||||||
|
|||||||
@@ -28,20 +28,16 @@ def _():
|
|||||||
|
|
||||||
@app.cell(hide_code=True)
|
@app.cell(hide_code=True)
|
||||||
def _(mo):
|
def _(mo):
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from bib.client import COLLECTIONS
|
from bib.client import COLLECTIONS
|
||||||
from bib.format import format_bibliography, format_citation
|
from bib.format import format_bibliography, format_citation
|
||||||
from bib.item import Download, Item, Manual, Regulation, Rule, Source
|
from bib.item import Download, Item, Manual, Regulation, Rule, Source
|
||||||
from bib.store import Store
|
from bib.store import Store
|
||||||
from bib.tag import Tag, filter_tags
|
from bib.tag import Tag, filter_tags
|
||||||
|
from conf import connect, path as _conf_path
|
||||||
|
|
||||||
from conf import path as _conf_path
|
store = connect.bib()
|
||||||
|
|
||||||
BIB_DB = _conf_path("db.bib")
|
|
||||||
ZOTERO_DB = _conf_path("db.zotero")
|
ZOTERO_DB = _conf_path("db.zotero")
|
||||||
|
BIB_DB = _conf_path("db.bib")
|
||||||
store = Store(str(BIB_DB))
|
|
||||||
|
|
||||||
mo.md(f"""
|
mo.md(f"""
|
||||||
## 1. Connect
|
## 1. Connect
|
||||||
|
|||||||
@@ -40,13 +40,10 @@ def _():
|
|||||||
import inspect
|
import inspect
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import duckdb
|
|
||||||
import polars as pl
|
import polars as pl
|
||||||
|
from conf import connect
|
||||||
|
|
||||||
from conf import path as _conf_path
|
con = connect.duckdb()
|
||||||
|
|
||||||
DB_PATH = str(_conf_path("db.aco"))
|
|
||||||
con = duckdb.connect(DB_PATH, read_only=True)
|
|
||||||
|
|
||||||
def q(sql):
|
def q(sql):
|
||||||
"""Run SQL query and return a Polars DataFrame."""
|
"""Run SQL query and return a Polars DataFrame."""
|
||||||
|
|||||||
@@ -24,14 +24,10 @@ def _(mo):
|
|||||||
|
|
||||||
@app.cell(hide_code=True)
|
@app.cell(hide_code=True)
|
||||||
def _():
|
def _():
|
||||||
import duckdb
|
|
||||||
import polars as pl
|
import polars as pl
|
||||||
from pathlib import Path
|
from conf import connect
|
||||||
|
|
||||||
from conf import path as _conf_path
|
con = connect.duckdb()
|
||||||
|
|
||||||
DB_PATH = str(_conf_path("db.aco"))
|
|
||||||
con = duckdb.connect(DB_PATH, read_only=True)
|
|
||||||
|
|
||||||
def q(sql):
|
def q(sql):
|
||||||
return con.execute(sql).pl()
|
return con.execute(sql).pl()
|
||||||
|
|||||||
@@ -27,10 +27,8 @@ def _():
|
|||||||
def _(mo):
|
def _(mo):
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import polars as pl
|
import polars as pl
|
||||||
from pathlib import Path
|
|
||||||
from pyzotero import zotero
|
from pyzotero import zotero
|
||||||
|
from conf import connect, path as _conf_path
|
||||||
from conf import path as _conf_path
|
|
||||||
|
|
||||||
ZOTERO_DB = _conf_path("db.zotero")
|
ZOTERO_DB = _conf_path("db.zotero")
|
||||||
|
|
||||||
@@ -40,12 +38,12 @@ def _(mo):
|
|||||||
Database path: `{ZOTERO_DB}`
|
Database path: `{ZOTERO_DB}`
|
||||||
Exists: **{ZOTERO_DB.exists()}**
|
Exists: **{ZOTERO_DB.exists()}**
|
||||||
""")
|
""")
|
||||||
return ZOTERO_DB, pl, sqlite3, zotero
|
return ZOTERO_DB, connect, pl, sqlite3, zotero
|
||||||
|
|
||||||
|
|
||||||
@app.cell(hide_code=True)
|
@app.cell(hide_code=True)
|
||||||
def _(ZOTERO_DB, sqlite3):
|
def _(connect, sqlite3):
|
||||||
db = sqlite3.connect(f"file:{ZOTERO_DB}?mode=ro", uri=True)
|
db = connect.zotero()
|
||||||
db.row_factory = sqlite3.Row
|
db.row_factory = sqlite3.Row
|
||||||
|
|
||||||
# Quick health check
|
# Quick health check
|
||||||
|
|||||||
Reference in New Issue
Block a user