29 lines
1 KiB
Python
29 lines
1 KiB
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)
|
|
res_json = res.json()
|
|
if 'error' in res_json:
|
|
print("API ERROR:", res_json['error'])
|
|
data = res_json.get('data', {})
|
|
cols = [c['name'] for c in data.get('cols', [])]
|
|
rows = data.get('rows', [])
|
|
return cols, rows
|
|
|
|
cols, rows = run_query("SELECT id, name, base_price FROM rooms WHERE id IN (50135711, 1014111, 1014112)")
|
|
for r in rows:
|
|
print(dict(zip(cols, r)))
|
|
|
|
cols, rows = run_query("SELECT id, reservation_id, amount, status FROM payments WHERE reservation_id IN (2147536324, 1707880780)")
|
|
for r in rows:
|
|
print(dict(zip(cols, r)))
|