Refine transaction amount parsing and improve banner closing in Ozon scripts:
- Handle fractional amounts during transaction parsing in mock server. - Add support for closing Google Play update banners in `Ozon` homepage handling logic.
This commit is contained in:
parent
d9479cd3ea
commit
d0330a509a
@ -200,14 +200,28 @@ bool CommonScript::runAppAndGoToHomeScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CommonScript::tryToCloseAllBannersOnHomePage(const QString &deviceId, const int width, const int height) {
|
bool CommonScript::tryToCloseAllBannersOnHomePage(const QString &deviceId, const int width, const int height) {
|
||||||
Node closeBannerOrDialogNode = xmlScreenParser.tryToFindBannerOrDialog(width, height);
|
bool closedAny = false;
|
||||||
if (closeBannerOrDialogNode.x() != -1 && closeBannerOrDialogNode.y() != -1) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
AdbUtils::makeTap(deviceId, closeBannerOrDialogNode.x(), closeBannerOrDialogNode.y());
|
bool closedThis = false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO тут все другие банеры попробовать закрыть
|
// Баннер Google Play "Доступно обновление" — появляется поверх Ozon при возврате на домашнюю
|
||||||
return false;
|
if (Node gpNode = xmlScreenParser.tryToFindGooglePlayBanner(width, height); !gpNode.isEmpty()) {
|
||||||
|
qDebug() << "[tryToCloseAllBannersOnHomePage] Google Play update banner detected, closing...";
|
||||||
|
AdbUtils::makeTap(deviceId, gpNode.x(), gpNode.y());
|
||||||
|
QThread::msleep(1500);
|
||||||
|
closedThis = true;
|
||||||
|
} else if (Node closeBannerOrDialogNode = xmlScreenParser.tryToFindBannerOrDialog(width, height);
|
||||||
|
closeBannerOrDialogNode.x() != -1 && closeBannerOrDialogNode.y() != -1) {
|
||||||
|
AdbUtils::makeTap(deviceId, closeBannerOrDialogNode.x(), closeBannerOrDialogNode.y());
|
||||||
|
QThread::msleep(500);
|
||||||
|
closedThis = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!closedThis) break;
|
||||||
|
closedAny = true;
|
||||||
|
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(deviceId, ++m_counter));
|
||||||
|
}
|
||||||
|
return closedAny;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CommonScript::goToAllProducts(
|
bool CommonScript::goToAllProducts(
|
||||||
|
|||||||
@ -226,11 +226,12 @@ def parse_ozon_rows(xml):
|
|||||||
continue
|
continue
|
||||||
if "Расход" in text or "Доход" in text:
|
if "Расход" in text or "Доход" in text:
|
||||||
continue
|
continue
|
||||||
am = re.search(r"([+\-−])\s*(\d[\d\s\u202f]*)", text)
|
am = re.search(r"([+\-−])\s*(\d[\d\s\u202f]*(?:[,.]\d{1,2})?)", text)
|
||||||
if not am:
|
if not am:
|
||||||
continue
|
continue
|
||||||
sign = -1 if am.group(1) in ("-", "−") else 1
|
sign = -1 if am.group(1) in ("-", "−") else 1
|
||||||
amount = sign * int(re.sub(r"[\s\u202f]", "", am.group(2)))
|
raw = re.sub(r"[\s\u202f]", "", am.group(2)).replace(",", ".")
|
||||||
|
amount = sign * (float(raw) if "." in raw else int(raw))
|
||||||
rows.append({"text": text, "cx": (x1+x2)//2, "cy": cy, "amount": amount})
|
rows.append({"text": text, "cx": (x1+x2)//2, "cy": cy, "amount": amount})
|
||||||
rows.sort(key=lambda r: r["cy"])
|
rows.sort(key=lambda r: r["cy"])
|
||||||
return rows
|
return rows
|
||||||
@ -275,7 +276,7 @@ def parse_dushanbe_rows(xml):
|
|||||||
for p in parts:
|
for p in parts:
|
||||||
p = p.strip()
|
p = p.strip()
|
||||||
try:
|
try:
|
||||||
amount = int(float(p))
|
amount = float(p.replace(",", "."))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if re.match(r"^\s*\d{1,2}:\d{2}(:\d{2})?\s*$", p):
|
if re.match(r"^\s*\d{1,2}:\d{2}(:\d{2})?\s*$", p):
|
||||||
@ -306,7 +307,14 @@ def extract_dushanbe_detail(xml):
|
|||||||
def short_label(amount, time_str):
|
def short_label(amount, time_str):
|
||||||
sign = "plus" if amount >= 0 else "minus"
|
sign = "plus" if amount >= 0 else "minus"
|
||||||
t = time_str.replace(":", "") if time_str else "unk"
|
t = time_str.replace(":", "") if time_str else "unk"
|
||||||
return f"{sign}_{abs(amount)}_{t}"
|
a = abs(amount)
|
||||||
|
if isinstance(a, float):
|
||||||
|
rub = int(a)
|
||||||
|
kop = int(round((a - rub) * 100))
|
||||||
|
amt = f"{rub}_{kop:02d}" if kop else f"{rub}"
|
||||||
|
else:
|
||||||
|
amt = f"{a}"
|
||||||
|
return f"{sign}_{amt}_{t}"
|
||||||
|
|
||||||
|
|
||||||
def collect_tasks(serial, bank, mid, device_tz, kopecks, prefix):
|
def collect_tasks(serial, bank, mid, device_tz, kopecks, prefix):
|
||||||
@ -416,7 +424,7 @@ def collect_tasks(serial, bank, mid, device_tz, kopecks, prefix):
|
|||||||
while label in seen: label += "_2"
|
while label in seen: label += "_2"
|
||||||
seen.add(label)
|
seen.add(label)
|
||||||
tasks.append({"bank_name": bank, "material_id": mid, "type": "FETCH_TRANSACTIONS",
|
tasks.append({"bank_name": bank, "material_id": mid, "type": "FETCH_TRANSACTIONS",
|
||||||
"body": {"amount": row["amount"] * kopecks, "created_at": cat},
|
"body": {"amount": int(round(row["amount"] * kopecks)), "created_at": cat},
|
||||||
"_tag": f"{prefix}_{task_num:02d}_{label}"})
|
"_tag": f"{prefix}_{task_num:02d}_{label}"})
|
||||||
|
|
||||||
# Помечаем даты как завершённые: все даты кроме последней на экране
|
# Помечаем даты как завершённые: все даты кроме последней на экране
|
||||||
@ -477,7 +485,7 @@ def collect_tasks(serial, bank, mid, device_tz, kopecks, prefix):
|
|||||||
if not date_s or not time_s:
|
if not date_s or not time_s:
|
||||||
print(" SKIP"); continue
|
print(" SKIP"); continue
|
||||||
|
|
||||||
amount = int(float(amt_s)) if amt_s else (row["amount"] or 0)
|
amount = float(amt_s.replace(",", ".")) if amt_s else (row["amount"] or 0)
|
||||||
fmt = "%d.%m.%Y %H:%M:%S" if len(time_s) > 5 else "%d.%m.%Y %H:%M"
|
fmt = "%d.%m.%Y %H:%M:%S" if len(time_s) > 5 else "%d.%m.%Y %H:%M"
|
||||||
# Душанбе показывает время в Asia/Dushanbe (UTC+5), не в таймзоне устройства
|
# Душанбе показывает время в Asia/Dushanbe (UTC+5), не в таймзоне устройства
|
||||||
dushanbe_tz = timezone(timedelta(hours=5))
|
dushanbe_tz = timezone(timedelta(hours=5))
|
||||||
@ -494,7 +502,7 @@ def collect_tasks(serial, bank, mid, device_tz, kopecks, prefix):
|
|||||||
while label in seen: label += "_2"
|
while label in seen: label += "_2"
|
||||||
seen.add(label)
|
seen.add(label)
|
||||||
tasks.append({"bank_name": bank, "material_id": mid, "type": "FETCH_TRANSACTIONS",
|
tasks.append({"bank_name": bank, "material_id": mid, "type": "FETCH_TRANSACTIONS",
|
||||||
"body": {"amount": amount * kopecks, "created_at": cat},
|
"body": {"amount": int(round(amount * kopecks)), "created_at": cat},
|
||||||
"_tag": f"{prefix}_{task_num:02d}_{label}"})
|
"_tag": f"{prefix}_{task_num:02d}_{label}"})
|
||||||
|
|
||||||
scroll_count += 1
|
scroll_count += 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user