forked from YuviGold/metabase_export_import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metabase_export.py
69 lines (46 loc) · 1.45 KB
/
metabase_export.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from pathlib import Path
from typer import Option, Typer
from typing_extensions import Annotated
import metabase
app = Typer()
db_name: str
data_dir: Path
raw_mode: bool
metabaseAPI: metabase.MetabaseApi
@app.command('all')
def export_all():
fields()
cards()
dashboards()
metrics()
@app.command()
def fields():
metabaseAPI.export_fields_to_csv(db_name, str(data_dir))
@app.command()
def metrics():
metabaseAPI.export_metrics_to_json(db_name, str(data_dir), raw_mode)
@app.command()
def cards():
metabaseAPI.export_cards_to_json(db_name, str(data_dir), raw_mode)
@app.command()
def dashboards():
metabaseAPI.export_dashboards_to_json(db_name, str(data_dir), raw_mode)
@app.callback()
def common(api_url: Annotated[str, Option(envvar='MB_EXPORT_HOST')],
username: Annotated[str, Option(envvar='MB_EXPORT_USERNAME')],
password: Annotated[str, Option(envvar='MB_EXPORT_PASSWORD')],
database: Annotated[str, Option(envvar='MB_EXPORT_DB')],
data: Annotated[Path, Option(envvar='MB_DATA_DIR')],
verbose: bool = False,
dry_run: bool = False,
raw: bool = False):
global db_name, data_dir, metabaseAPI, raw_mode
metabaseAPI = metabase.MetabaseApi(api_url, username, password, verbose, dry_run)
db_name = database
data_dir = data
raw_mode = raw
data_dir.mkdir(exist_ok=True)
def main():
app()
if __name__ == '__main__':
main()