Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Improve data export #205

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading