forked from YuviGold/metabase_export_import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metabase_import.py
65 lines (43 loc) · 1.51 KB
/
metabase_import.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
from pathlib import Path
from typing import Optional
from typer import Argument, Option, Typer
from typing_extensions import Annotated
import metabase
app = Typer()
db_name: str
data_dir: Path
metabaseAPI: metabase.MetabaseApi
@app.command('all')
def import_all(collection: str):
fields()
metrics()
cards(collection)
dashboards(collection)
@app.command()
def fields(field_ids: Annotated[Optional[list[str]], Argument()] = None):
metabaseAPI.import_fields_from_csv(db_name, str(data_dir), field_ids)
@app.command()
def metrics():
metabaseAPI.import_metrics_from_json(db_name, str(data_dir))
@app.command()
def cards(collection: str):
metabaseAPI.import_cards_from_json(db_name, str(data_dir), collection)
@app.command()
def dashboards(collection: str):
metabaseAPI.import_dashboards_from_json(db_name, str(data_dir), collection)
@app.callback()
def common(api_url: Annotated[str, Option(envvar='MB_IMPORT_HOST')],
username: Annotated[str, Option(envvar='MB_IMPORT_USERNAME')],
password: Annotated[str, Option(envvar='MB_IMPORT_PASSWORD')],
database: Annotated[str, Option(envvar='MB_IMPORT_DB')],
data: Annotated[Path, Option(envvar='MB_DATA_DIR')],
verbose: bool = False,
dry_run: bool = False):
global db_name, data_dir, metabaseAPI
metabaseAPI = metabase.MetabaseApi(api_url, username, password, verbose, dry_run)
db_name = database
data_dir = data
def main():
app()
if __name__ == '__main__':
main()