-
Notifications
You must be signed in to change notification settings - Fork 43
/
tasks.py
53 lines (47 loc) · 1.23 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from pathlib import Path
from invoke import task
@task
def export(c, dest="data"):
"""Export data to a few formats files."""
tables = {
"elements",
"groups",
"ionicradii",
"ionizationenergies",
"isotopedecaymodes",
"isotopes",
"oxidationstates",
"phasetransitions",
"propertymetadata",
"scattering_factors",
"screeningconstants",
"series",
}
formats = [
"csv",
"html",
"json",
"markdown",
]
root = Path(f"{dest}")
root.mkdir(exist_ok=True)
for fmt in formats:
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};' > {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(
f"sqlite3 mendeleev/elements.db .dump > {path}/mendeleev.sql",
echo=True,
pty=True,
)
print("done")