Skip to content

Commit

Permalink
Add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedasif1 committed Oct 14, 2022
1 parent ec03f1f commit 0227566
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/ptcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Ptcl {
let response = await this.submitForm(data);
const { billUrl, details } = await this.followRedirect(response);
console.log(details);
if (status['billMonth'] && details['billMonth'] === status['billMonth']) {
if (status && status['billMonth'] && details['billMonth'] === status['billMonth']) {
console.log('New bill does not exist');
} else {
await this.downloadPdf(billUrl, details);
Expand Down Expand Up @@ -83,7 +83,7 @@ class Ptcl {
async downloadPdf(downloadUrl, accountStatus) {
console.log('Downloading bill for phone:', this.billData['phone']);
const parsedBillMonth = parse(`10-${accountStatus.billMonth}`, 'dd-MM-yyyy', new Date());
Utils.downloadWithCurl(downloadUrl, this.cookies, this.billData, parsedBillMonth, `PTCL-${this.billData['phone']}.pdf`)
return Utils.downloadWithCurl(downloadUrl, this.cookies, this.billData, parsedBillMonth, `PTCL-${this.billData['phone']}.pdf`)
}

async readHiddenFields(response) {
Expand Down
10 changes: 9 additions & 1 deletion app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ const Utils = {

downloadWithCurl: async (pdfUrl, cookies, billData, billMonthDate, fileName) => {
const billMonthFinal = format(billMonthDate, 'yyyy-MM');
const command = `curl '${pdfUrl}' -H 'Cookie: ${cookies}' -o ${DOWNLOADS_PATH}/${billMonthFinal}/${billData['tag']}/${fileName}`;
let command = `curl '${pdfUrl}' -H 'Cookie: ${cookies}' -o ${DOWNLOADS_PATH}/${billMonthFinal}/${billData['tag']}/${fileName}`;
console.log(command);
const { stdout, stderr } = await execPromise(command);

console.log(stdout);
console.log(stderr);

//set permissions
command = `chmod +r "${DOWNLOADS_PATH}/${billMonthFinal}/${billData['tag']}/${fileName}"`;
Utils.log(command);
await execPromise(command);

},

saveWithWget: async (url, isPdf, billData, billMonthDate) => {
Expand Down

0 comments on commit 0227566

Please sign in to comment.