Skip to content

Commit

Permalink
fix: számlakeresés űrlap elküldés javítva (closes #35)
Browse files Browse the repository at this point in the history
  • Loading branch information
juzraai committed Jan 27, 2024
1 parent bbcc83f commit dad5969
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/dijnet-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ export default class DijnetAgent {
/**
* Submits bill search form.
*/
async submitBillSearchForm() {
async submitBillSearchForm(token) {
this.checkIfLoggedIn();
this.checkBillSearchForm();
const body =
'vfw_form=szamla_search_submit&vfw_coll=szamla_search_params&regszolgid=&szlaszolgid=&datumtol=&datumig=';
const body = `vfw_form=szamla_search_submit&vfw_token=${token}&vfw_coll=szamla_search_params&szlaszolgnev=&regszolgid=&datumtol=&datumig=`;
await this.browser.submit('/control/szamla_search_submit', body);
}

Expand Down
10 changes: 10 additions & 0 deletions src/dijnet-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import deburr from 'lodash.deburr';
import Bill from './bill.js';
import BillFile from './bill-file.js';

export function parseBillSearchToken(body) {
const $ = cheerio.load(body);
const token = $('input[name=vfw_token]')?.attr('value');
if (!token) {
throw new Error('Nem találom a vfw_token-t.');
}

return token;
}

/**
* @param {string} body Response body, it should be the HTML code of a bill list page
* @returns {Bill[]} Bills' metadata
Expand Down
9 changes: 7 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import { getConfig } from './configurator.js';
import DijnetAgent from './dijnet-agent.js';
import DijnetBrowser from './dijnet-browser.js';
import { parseBillDownloads, parseBillSearchResults } from './dijnet-parser.js';
import {
parseBillDownloads,
parseBillSearchResults,
parseBillSearchToken,
} from './dijnet-parser.js';
import Logger from './logger.js';
import Repo from './repo.js';

Expand All @@ -24,7 +28,8 @@ export async function start() {

logger.info('Számlák keresése...');
await agent.openBillSearch();
await agent.submitBillSearchForm();
const token = parseBillSearchToken(agent.browser.lastNavigationResponse.body);
await agent.submitBillSearchForm(token);
let bills = parseBillSearchResults(agent.browser.lastNavigationResponse.body);
const allBillsCount = bills.length;
bills = bills.filter(repo.isNew.bind(repo));
Expand Down

0 comments on commit dad5969

Please sign in to comment.