Skip to content

Commit

Permalink
improve export function (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmmentel authored Nov 6, 2024
1 parent 6e014a0 commit 10a444d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


@task
def export(c):
def export(c, dest="data"):
"""Export data to a few formats files."""
tables = [
tables = {
"elements",
"groups",
"ionicradii",
Expand All @@ -14,9 +14,11 @@ def export(c):
"isotopes",
"oxidationstates",
"phasetransitions",
"propertymetadata",
"scattering_factors",
"screeningconstants",
"series",
]
}

formats = [
"csv",
Expand All @@ -25,20 +27,26 @@ def export(c):
"markdown",
]

root = Path(f"{dest}")
root.mkdir(exist_ok=True)

for fmt in formats:
Path(f"data/{fmt}").mkdir(exist_ok=True)
path = root.joinpath(fmt)
path.mkdir(exist_ok=True)
for table in tables:
print(f"Exporting {table} to {fmt} ... ", end="")
c.run(
f"sqlite3 -{fmt} mendeleev/elements.db 'SELECT * FROM {table};' > data/{fmt}/{table}.{fmt}",
f"sqlite3 -{fmt} mendeleev/elements.db 'SELECT * FROM {table};' > {path}/{table}.{fmt}",
echo=True,
)
print("done")

# SQL dump
print("Creating SQL files with the data ... ", end="")
path = root.joinpath("sql")
path.mkdir(exist_ok=True)
c.run(
"sqlite3 mendeleev/elements.db .dump > data/sql/elements.sql",
f"sqlite3 mendeleev/elements.db .dump > {path}/mendeleev.sql",
echo=True,
pty=True,
)
Expand Down

0 comments on commit 10a444d

Please sign in to comment.