ehsan-dashboards/dashboards/check_matview.py

21 lines
868 B
Python

import requests
url = 'https://metabase.ekeepa-dev.ir/api/session'
creds = {'username': 'Fallahi.hamed@gmail.com', 'password': 'r5kivS&JR4d2BfUaS95xCDY^NxX*'}
r = requests.post(url, json=creds, timeout=15)
token = r.json().get('id')
headers = {'X-Metabase-Session': token}
def run_query(sql, db=2):
res = requests.post('https://metabase.ekeepa-dev.ir/api/dataset', headers=headers, json={
'database': db,
'type': 'native',
'native': {'query': sql}
}, timeout=30)
data = res.json().get('data', {})
cols = [c['name'] for c in data.get('cols', [])]
rows = data.get('rows', [])
return cols, rows
print(run_query("SELECT table_schema, table_name, table_type FROM information_schema.tables WHERE table_name LIKE '%hamed%'"))
print(run_query("SELECT matviewname, definition FROM pg_matviews WHERE matviewname = 'v_hamed'"))