Browse Source

Cleaning stuff

master
Jérôme 6 years ago
parent
commit
e711d48329
2 changed files with 8 additions and 13 deletions
  1. +6
    -11
      index.js
  2. +2
    -2
      manifest.konnector

+ 6
- 11
index.js View File

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


return rq(options) return rq(options)
.then(res => { .then(res => {
//const isNoLocation = !res.headers.location
const isNot200 = res.statusCode !== 200 const isNot200 = res.statusCode !== 200
//const isError = res.headers.location && res.headers.location.indexOf('error') !== -1
if (isNot200) { if (isNot200) {
log('info', 'Authentification error') log('info', 'Authentification error')
throw new Error('LOGIN_FAILED') 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 ($) { function parsePage ($) {
const bills = [] const bills = []

$('.invoice-line').each(function () { $('.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 billId = $(this).data('invoice-id')

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


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



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


let bill = { let bill = {


+ 2
- 2
manifest.konnector View File

@@ -2,8 +2,8 @@
"version": "1.0.0", "version": "1.0.0",
"name": "Enercoop Cozy konnector", "name": "Enercoop Cozy konnector",
"type": "node", "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", "source": "https://gitlab.allella.io/dje/cozy-konnector-enercoop",
"locales": { "locales": {
"fr": { "fr": {


Loading…
Cancel
Save