Przeglądaj źródła

Cleaning stuff

master
Jérôme 6 lat temu
rodzic
commit
e711d48329
2 zmienionych plików z 8 dodań i 13 usunięć
  1. +6
    -11
      index.js
  2. +2
    -2
      manifest.konnector

+ 6
- 11
index.js Wyświetl plik

@@ -40,9 +40,7 @@ function logIn (fields) {

return rq(options)
.then(res => {
//const isNoLocation = !res.headers.location
const isNot200 = res.statusCode !== 200
//const isError = res.headers.location && res.headers.location.indexOf('error') !== -1
if (isNot200) {
log('info', 'Authentification error')
throw new Error('LOGIN_FAILED')
@@ -57,33 +55,30 @@ function logIn (fields) {
})
}

// Parse the fetched page to extract bill data.
// Parse the fetched DOM page to extract bill data.
function parsePage ($) {
const bills = []

$('.invoice-line').each(function () {
//console.log($(this).html())
//one bill per line = a <li> with 'invoice-id' data-attr
let billId = $(this).data('invoice-id')

let amount = $(this).find('.amount').text()
amount = amount.replace('€','')
amount = amount.replace(',', '.').trim()
amount = parseFloat(amount)

//gets pdf download URL
let pdfUrl = $(this).find('a > i').data('url')
pdfUrl = baseUrl + pdfUrl


//pdfUrl = `https://adsl.free.fr/${pdfUrl}`
//<French month>-YYYY format (Décembre - 2017)
let billDate = $(this).find('.invoiceDate').text().trim()
let monthAndYear = billDate.split('-')
let billYear = monthAndYear[0].trim()
let billMonth = monthAndYear[1].trim()
//console.log(billMonth.toLowerCase())
billMonth = moment.months().indexOf(billMonth.toLowerCase()) + 1
billMonth = billMonth < 10 ? '0' + billMonth : billMonth
//console.log(billMonth+"*"+billYear + "-----|" + billId + '->' + amount + "|||"+pdfUrl)

//let month = "12"//pdfUrl.split('&')[2].split('=')[1]
let date = moment(billYear + billMonth, 'YYYYMM')

let bill = {


+ 2
- 2
manifest.konnector Wyświetl plik

@@ -2,8 +2,8 @@
"version": "1.0.0",
"name": "Enercoop Cozy konnector",
"type": "node",
"slug": "konnectorslug",
"description": "Collects your Enercoop's bills",
"slug": "enercoopslug",
"description": "Collects your Enercoop bills",
"source": "https://gitlab.allella.io/dje/cozy-konnector-enercoop",
"locales": {
"fr": {


Ładowanie…
Anuluj
Zapisz