Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Fix action
Browse files Browse the repository at this point in the history
  • Loading branch information
rodriguestiago0 committed Jun 21, 2024
1 parent 57a8273 commit 4ffb0e2
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 1,787 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
id: meta
uses: docker/metadata-action@v4
with:
images: rodriguestiago0/tinkactual
images: rodriguestiago0/myedenredactual


- name: Build and push Docker image
Expand Down
1 change: 0 additions & 1 deletion actual.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { getAppConfigFromEnv } = require("./config");
const actual = require("@actual-app/api");
const fs = require("fs");
const inquirer = require("inquirer");
let { q, runQuery } = require('@actual-app/api');


Expand Down
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const printSyncedAccounts = () => {
*/
module.exports = async (command, flags) => {
if (!command) {
console.log('Try "thinkactual --help"');
console.log('Try "myedenredactual --help"');
process.exit();
}

Expand Down
23 changes: 14 additions & 9 deletions edenredService.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
const { getAppConfigFromEnv } = require("./config");
const crypto = require('crypto');



const appConfig = getAppConfigFromEnv();

const login = async () => {

const authenticate = async () => {
u = {
userId: appConfig.EDENRED_USERNAME,
client_secret: appConfig.EDENRED_PASSWORD
password: appConfig.EDENRED_PASSWORD
};
const token = await fetch('https://www.myedenred.pt/edenred-customer/v2/authenticate/default?appVersion=1.0&appType=PORTAL&channel=WEB', {
method: 'POST',
body: JSON.stringify(u),
headers: {
'Content-type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
},
})
.then((response) => response.json())
.then((json) => json.data.token)
.catch((err) => {
console.error("error occured", err)
console.error("error occured", err);
return '';
});
return token
}
Expand All @@ -36,9 +37,9 @@ const getAllTransactions = async (token, accountId) => {
},
})
.then((response) => response.json())
.then((json) => json.movementList)
.then((json) => json.data.movementList)
.catch((err) => {
console.error("error occured", err)
console.error("error occured", err);
});

return transactions;
Expand All @@ -51,9 +52,13 @@ async function getTransactions(accountId) {
transactions.forEach(transaction => {
transactionID = crypto.createHash('sha256').update(transaction.transactionName+transaction.transactionDate+transaction.amount).digest('hex');

date = transaction.transactionDate.split("T")[0]
if (date < '2024-06-21') {
return;
}
parsedTransactions.push({
date: transaction.transactionDate,
amount: transaction.amount,
date: date,
amount: Math.trunc(transaction.amount * 100),
payee_name: transaction.transactionName,
imported_payee: transaction.transactionName,
imported_id: transactionID,
Expand Down
4 changes: 2 additions & 2 deletions engine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getAppConfigFromEnv, getConf } = require("./config");
const { getTransactions } = require("./edebredService.js");
const { getTransactions } = require("./edenredService.js");
const { initialize, importTransactions, finalize, listAccounts } = require("./actual.js");

const appConfig = getAppConfigFromEnv();
Expand All @@ -13,7 +13,7 @@ async function importMyEdenredTransactions() {
console.info("Importing transactions for account ", edenredAccountId)
var mappedtransactions = await getTransactions(edenredAccountId)
await importTransactions(actual, actualAccountID, mappedtransactions);
});
};

await finalize(actual);
}
Expand Down
Loading

0 comments on commit 4ffb0e2

Please sign in to comment.