diff --git a/.prettierrc b/.prettierrc index db0a25ac..e65c538d 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,4 +2,4 @@ "singleQuote": true, "semi": false, "printWidth": 120 -} \ No newline at end of file +} diff --git a/package.json b/package.json index 55d73618..8efae79e 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,14 @@ "prepush": "ava test" }, "lint-staged": { - "*.{css,md,json}": ["prettier --write", "git add"], - "*.{js}": ["eslint --fix", "git add"] + "*.{css,md,json}": [ + "prettier --write", + "git add" + ], + "*.{js}": [ + "eslint --fix", + "git add" + ] }, "engines": { "node": ">=10" @@ -21,7 +27,9 @@ "type": "git", "url": "git://github.com/devschile/huemul.git" }, - "keywords": ["hubot"], + "keywords": [ + "hubot" + ], "author": "Huemul", "private": true, "bugs": { @@ -122,6 +130,6 @@ "husky": "0.14.3", "lint-staged": "9.4.2", "nock": "9.2.6", - "prettier": "1.12.1" + "prettier": "2.0.5" } } diff --git a/scripts/portadas.js b/scripts/portadas.js index 4717b0c2..8595aa77 100644 --- a/scripts/portadas.js +++ b/scripts/portadas.js @@ -87,13 +87,11 @@ const diarios = { noSlashes: false }, tercera: { - url: - 'https://edition.pagesuite-professional.co.uk/get_image.aspx?w=550&pbid=33084897-397a-48cc-b3c0-3ce1ec447137&pnum=01&nocache=#DATE#', + url: 'https://kiosco.latercera.com/latest-issue-cover-image?collection=lt_diario_la_tercera_6_30&nocache=#DATE#', noSlashes: true }, cuarta: { - url: - 'https://edition.pagesuite-professional.co.uk/get_image.aspx?w=550&pbid=a94a1c16-2ebc-4ecc-b2bc-d60709ea4c26&pnum=01&nocache=#DATE#', + url: 'https://kiosco.lacuarta.com/latest-issue-cover-image?collection=lc_diario_la_cuarta&nocache=#DATE#', noSlashes: true }, estrellaarica: { @@ -301,46 +299,48 @@ const getPortada = (res, diario) => { const fecha = moment().subtract(daysPast, 'days') testUrl = diario.url.replace('#DATE#', formatDate(fecha, diario.noSlashes)) return new Promise((resolve, reject) => { - res - .http(testUrl) - .timeout(2000) - .get()((err, response, body) => { - if (err) return reject(err) - switch (response.statusCode) { - case 404: - daysPast++ - resolve(testUrl) - break - case 200: - ready = false - if (testUrl === endpointHxh) { - try { - var jsonHxh = JSON.parse(body) - testUrl = jsonHxh[0].esPortadaFalsa || diario.forcePortada ? jsonHxh[3].img : jsonHxh[0].img - const dateFromHxh = testUrl && testUrl.split('/')[4] - dateFromHxh && sendPortadaDate(res, moment(dateFromHxh, 'DDMMYY').toDate()) - resolve(testUrl) - } catch (err) { - reject(err) - } - } else { - sendPortadaDate(res, fecha) + res.http(testUrl).timeout(2000).get()((err, response, body) => { + if (err) return reject(err) + switch (response.statusCode) { + case 404: + daysPast++ + resolve(testUrl) + break + case 200: + ready = false + if (testUrl === endpointHxh) { + try { + var jsonHxh = JSON.parse(body) + testUrl = jsonHxh[0].esPortadaFalsa || diario.forcePortada ? jsonHxh[3].img : jsonHxh[0].img + const dateFromHxh = testUrl && testUrl.split('/')[4] + dateFromHxh && sendPortadaDate(res, moment(dateFromHxh, 'DDMMYY').toDate()) resolve(testUrl) + } catch (err) { + reject(err) } - break - default: - resolve() - break - } - }) + } else { + sendPortadaDate(res, fecha) + resolve(testUrl) + } + break + case 302: + ready = false + sendPortadaDate(res, fecha) + resolve(testUrl) + break + default: + resolve() + break + } + }) }) } } ) } -module.exports = robot => { - robot.respond(/portada (.*)/i, res => { +module.exports = (robot) => { + robot.respond(/portada (.*)/i, (res) => { const nombre = res.match[1] .toLowerCase() .replace(/^(las |la |el |le |the |o |il )/, '') @@ -361,11 +361,11 @@ module.exports = robot => { res.send(listaPortadas()) } else if (nombre in diarios) { getPortada(res, diarios[nombre]) - .then(result => { + .then((result) => { if (!result) return res.send('No hay portada disponible') res.send(result) }) - .catch(err => { + .catch((err) => { robot.emit('error', err, res, 'portadas') }) } else { diff --git a/yarn.lock b/yarn.lock index 923deb64..0eaa9ca6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5341,9 +5341,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@1.12.1: - version "1.12.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.12.1.tgz#c1ad20e803e7749faf905a409d2367e06bbe7325" +prettier@2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4" + integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg== pretty-ms@^0.2.1: version "0.2.2"