25 lines
909 B
Python
25 lines
909 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)
|
|
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, base_price, number_of_players FROM reservations WHERE id IN (2147536324, 1707880780)")
|
|
for r in rows:
|
|
print(dict(zip(cols, r)))
|