41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
import requests
|
|
import json
|
|
from collections import Counter
|
|
|
|
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
|
|
|
|
# 1. Analyze v_hamed for these rooms
|
|
cols, rows = run_query("SELECT roomid, otagh, status, payment_status, payment_status_title, paid_amount, paid_amount_success, buydate_jalali, buydatetime FROM v_hamed WHERE roomid IN (50135711, 1014111, 1014112)")
|
|
print("=== BREAKDOWN OF V_HAMED ===")
|
|
counts = Counter()
|
|
for r in rows:
|
|
d = dict(zip(cols, r))
|
|
key = (d['otagh'], d['status'], d['payment_status'], d['payment_status_title'])
|
|
counts[key] += 1
|
|
|
|
for k, v in counts.items():
|
|
print(f"Room: {k[0]} | Status: {k[1]} | PaymentStatus: {k[2]} | Title: {k[3]} => Count: {v}")
|
|
|
|
# 2. Check if there are any pay_backs or refunds in DB 2 or DB 4
|
|
print("\n=== CHECK PAY_BACKS TABLE ===")
|
|
pb_cols, pb_rows = run_query("SELECT * FROM pay_backs LIMIT 5")
|
|
print("Pay_backs columns:", pb_cols)
|
|
pb_cols_all, pb_rows_all = run_query(f"SELECT * FROM pay_backs WHERE room_id IN (50135711, 1014111, 1014112)")
|
|
print("Pay backs for these rooms:", len(pb_rows_all))
|
|
for r in pb_rows_all:
|
|
print(dict(zip(pb_cols_all, r)))
|