Skip to content

Commit

Permalink
Version 1.1.0
Browse files Browse the repository at this point in the history
- Implemented EasyMail
- Updated README.md
  • Loading branch information
ComradeTurtle committed Apr 7, 2021
1 parent c4af883 commit 3c99d36
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ Node.js module that interfaces with Greek courier companies.
- ACS Courier (acscourier.net)
- Γενική Ταχυδρομική (taxydromiki.com)
- Speedex (speedex.com)
- EasyMail (easymail.gr)
- ..and more to come!

## Usage example
`npm i courier-api`
```js
const geniki = new(require("courier-api").geniki);
const speedex = new(require("courier-api").speedex);
const geniki = new(require("courier-api").geniki);
const easymail = new(require("courier-api").acs);
const elta = new(require("courier-api").elta);
const acs = new(require("courier-api").acs);


(async () => {
await elta.get("TRACK_ID")
.then((r) => console.log(r))
Expand All @@ -32,11 +35,15 @@ const acs = new(require("courier-api").acs);
await acs.get('TRACK_ID')
.then((r) => console.log(r))
.catch((e) => console.error(e));

await easymail.get('TRACK_ID')
.then((r) => console.log(r))
.catch((e) => console.error(e));
});
```
or
```js
const { geniki, speedex, elta, acs } = require('courier-api');
const { geniki, speedex, elta, acs, easymail } = require('courier-api');
(async () => {
await new elta().get('TRACK_ID')
.then((result) => console.log(result))
Expand Down
47 changes: 40 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ class elta {
.then((results) => {
const data = results.data;
let array = data.result[tr].result;

if (!(data.status === 1)) reject({ "status": "no result" });
if (data.result[tr].status === 2) reject({ "status": "no result" });
if (array === "wrong number") reject({ "status": "no result" });

if (!(data.status === 1) || data.result[tr].status === 2 || array === "wrong number") reject({ "status": "no result" });
resolve(array);
}).catch((err) => {
reject(err);
Expand All @@ -31,7 +27,6 @@ class geniki {
let number = 0;
let obj = 0;
let trData = {};
let trArray = [];

Array.prototype.forEach.call(trDOM.window.document.getElementsByTagName('div'), (e) => {

Expand Down Expand Up @@ -126,4 +121,42 @@ class acs {
}
}

module.exports = { elta, geniki, speedex, acs };
class easymail {
get(tr) {
return new Promise(async(resolve, reject) => {
const data = await axios.get(`https://trackntrace.easymail.gr/${tr}`);
const { JSDOM } = jsdom;
const response = data.data;
const dom = new JSDOM(response);
let number = 0;
let obj = 0;
let trData = {};

Array.prototype.forEach.call(dom.window.document.getElementsByClassName('table-hover'), (e) => {
Array.prototype.forEach.call(e.getElementsByTagName('td'), (a) => {
if (!trData[obj]) trData[obj] = {};
if (a.innerHTML.includes('/')) {
if (a.innerHTML.includes('<a')) return;
trData[obj].date = a.innerHTML.split(' ')[0];
trData[obj].time = a.innerHTML.split(' ')[1].substring(0, a.innerHTML.split(' ')[1].length - 3);
} else if (a.innerHTML == a.innerHTML.toUpperCase()) {
trData[obj].place = a.innerHTML.toUpperCase();
} else trData[obj].status = a.innerHTML;

number += 1;
if (number == 3) {
number = 0;
obj += 1;
}
})
if (Object.keys(trData).length < 1) reject({ "status": "no result" });
let array = Object.values(trData);
array.reverse();
array.pop();
resolve(array);
})
})
}
}

module.exports = { elta, geniki, speedex, acs, easymail };

0 comments on commit 3c99d36

Please sign in to comment.