Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multiple accounts on beinleumi base #842

Merged
32 changes: 27 additions & 5 deletions src/scrapers/base-beinleumi-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async function getAccountNumber(page: Page) {
return (option as HTMLElement).innerText;
});

return selectedSnifAccount.replace('/', '_');
return selectedSnifAccount.replace('/', '_').trim();
}

async function checkIfHasNextPage(page: Page) {
Expand Down Expand Up @@ -281,15 +281,37 @@ async function fetchAccountData(page: Page, startDate: Moment) {
};
}

// TODO: Add support of multiple accounts
async function getAccountIdsBySelector(page: Page): Promise<string[]> {
const accountsIds = await page.evaluate(() => {
const selectElement = document.getElementById('account_num_select');
const options = selectElement ? selectElement.querySelectorAll('option') : [];
if (!options) return [];
return Array.from(options, (option) => option.value);
});
return accountsIds;
}

async function fetchAccounts(page: Page, startDate: Moment) {
const accounts: TransactionsAccount[] = [];
const accountData = await fetchAccountData(page, startDate);
accounts.push(accountData);
const accountsIds = await getAccountIdsBySelector(page);
if (!accountsIds.length) {
const accountData = await fetchAccountData(page, startDate);
accounts.push(accountData);
} else {

for (const accountId of accountsIds) {
if (accountsIds.length > 1) {
await page.select('#account_num_select', accountId);
await waitUntilElementFound(page, '#account_num_select', true);
}
nisan-tagar marked this conversation as resolved.
Show resolved Hide resolved
const accountData = await fetchAccountData(page, startDate);
accounts.push(accountData);
}
}
return accounts;
}

type ScraperSpecificCredentials = {username: string, password: string};
type ScraperSpecificCredentials = { username: string, password: string };

class BeinleumiGroupBaseScraper extends BaseScraperWithBrowser<ScraperSpecificCredentials> {
BASE_URL = '';
Expand Down
Loading