Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix latercera portada #625

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"singleQuote": true,
"semi": false,
"printWidth": 120
}
}
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,7 +27,9 @@
"type": "git",
"url": "git://github.com/devschile/huemul.git"
},
"keywords": ["hubot"],
"keywords": [
"hubot"
],
"author": "Huemul",
"private": true,
"bugs": {
Expand Down Expand Up @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un version bump debería estar en un PR aparte

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De hecho este cambio completo debería ser un PR aparte, no es de latercera este cambio?

}
}
76 changes: 38 additions & 38 deletions scripts/portadas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No soy muy fan del estilo, pero la indentación debería ser igual al archivo original

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entonces prettier no está configurado en el proyecto, no? @gmq

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:
PotterSys marked this conversation as resolved.
Show resolved Hide resolved
ready = false
sendPortadaDate(res, fecha)
resolve(testUrl)
Copy link
Collaborator

@PotterSys PotterSys May 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En este caso, debería devolver el header Location que devuelve el servidor. Eso sí, hay que chequear que Location != testUrl para evitar caer en un bucle infinito (si son iguales, debería indicar que no hay portada)

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 )/, '')
Expand All @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Comment on lines +5344 to +5347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta magia debería estar en un PR aparte


pretty-ms@^0.2.1:
version "0.2.2"
Expand Down