Improve transaction amount extraction in GetLastTransactionsScript by using regex to support varying field positions across formats. Adjust logic for compatibility with 5- and 6-line DCWallet and P2P formats.
This commit is contained in:
parent
51dc69dbd6
commit
0b60109732
@ -453,13 +453,17 @@ void GetLastTransactionsScript::doStart() {
|
||||
}
|
||||
|
||||
// 2. Собираем View-транзакции (формат Выписки)
|
||||
// Два формата content-desc:
|
||||
// a) DCWallet/*** — старый: DCWallet*WDC...\ncard\namount\nописание\n HH:MM:SS
|
||||
// b) P2P — новый: Сегодня|dd.MM.yyyy\ncard\ncard\namount\nописание\n HH:MM:SS
|
||||
// Известные форматы content-desc (всё через '\n'):
|
||||
// a) DCWallet (старый, 5 строк): DCWallet*WDC...\ncard\namount\nописание\n HH:MM:SS
|
||||
// b) DCWallet (новый, 6 строк): DCWallet*WDC...\nphone-card-\ncard_owner\namount\nописание\n HH:MM:SS
|
||||
// c) P2P: Сегодня|dd.MM.yyyy\ncard\ncard\namount\nописание\n HH:MM:SS
|
||||
// Позиция amount уехала между версиями приложения, поэтому ищем по
|
||||
// паттерну "[-]?digits.dd" среди всех строк — устойчиво к перестановке полей.
|
||||
static const QRegularExpression reTime(R"(\d{2}:\d{2}:\d{2})");
|
||||
static const QRegularExpression reDateOrToday(
|
||||
QString("^(?:\\d{2}\\.\\d{2}\\.\\d{4}|%1|%2)$")
|
||||
.arg(QString::fromUtf8("Сегодня"), QString::fromUtf8("Вчера")));
|
||||
static const QRegularExpression reAmountLine(R"(^-?\d+\.\d{2}$)");
|
||||
QList<VypiskaItem> items;
|
||||
for (const Node &n : xmlScreenParser.findAllNodes()) {
|
||||
if (n.className != "android.view.View") continue;
|
||||
@ -475,10 +479,14 @@ void GetLastTransactionsScript::doStart() {
|
||||
|
||||
VypiskaItem it;
|
||||
bool ok = false;
|
||||
// В P2P формате amount на позиции [3] (после даты, двух карт), в DCWallet — [2]
|
||||
const int amtIdx = isP2P ? 3 : 2;
|
||||
if (amtIdx >= lines.size()) continue;
|
||||
it.amount = lines[amtIdx].trimmed().toDouble(&ok);
|
||||
// Ищем строку вида "-?\d+\.\d{2}" — устойчиво и к 5-, и к 6-строчному
|
||||
// DCWallet, и к P2P. Карты с пробелами ("9762 0002 ...") и текстовые
|
||||
// поля не подпадают под паттерн.
|
||||
for (const QString &line : lines) {
|
||||
if (!reAmountLine.match(line.trimmed()).hasMatch()) continue;
|
||||
it.amount = line.trimmed().toDouble(&ok);
|
||||
if (ok) break;
|
||||
}
|
||||
if (!ok) continue;
|
||||
it.time = last;
|
||||
it.node = n;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user