Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(scripts): se corrige zona horaria de chile
  • Loading branch information
lgaticaq committed Jun 11, 2018
1 parent 280375b commit 19fcd98
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
4 changes: 2 additions & 2 deletions scripts/gardel.js
Expand Up @@ -21,7 +21,7 @@ module.exports = function gardel(robot) {
moment.locale('es')

robot.respond(/gardel|cu[aá]ndo pagan/, function(msg) {
var today = moment(`${moment().format('YYYY-MM-DD')}T00:00:00-03:00`)
var today = moment(`${moment().format('YYYY-MM-DD')}T00:00:00-04:00`)
var lastBusinessDayMoment = moment()
.endOf('month')
.isBusinessDay()
Expand All @@ -30,7 +30,7 @@ module.exports = function gardel(robot) {
.endOf('month')
.prevBusinessDay()
var dateLastBusinessDay = lastBusinessDayMoment.format('YYYY-MM-DD')
var lastBusinessDay = moment(`${dateLastBusinessDay}T00:00:00-03:00`)
var lastBusinessDay = moment(`${dateLastBusinessDay}T00:00:00-04:00`)
var dayMessage = moment.duration(lastBusinessDay.diff(today)).humanize()
var dayCount = lastBusinessDay.diff(today, 'days')
var message = ''
Expand Down
43 changes: 28 additions & 15 deletions scripts/temblor.js
Expand Up @@ -15,19 +15,20 @@

module.exports = robot => {
robot.respond(/temblores( .*)?/i, res => {
const country = res.match[1] ? (res.match[1]).trim().toUpperCase() : null
const country = res.match[1] ? res.match[1].trim().toUpperCase() : null
const minMagnitude = 6 // Con un temblor menor a 6 grados ni me muevo de la silla menos de la cama asi q este es el mínimo.
const fetch = robot
.http('https://earthquake.usgs.gov')
.path('/fdsnws/event/1/query')
.query({format: 'geojson', minmagnitude: minMagnitude}) // {starttime: 'YYYY-MM-DDTHH:mm:ss-03:00'}
.query({ format: 'geojson', minmagnitude: minMagnitude }) // {starttime: 'YYYY-MM-DDTHH:mm:ss-04:00'}

fetch.get()((error, response, body) => {
if (error) return robot.emit('error', error, res)
if (response.statusCode !== 200) return robot.emit('error', new Error(`Response statusCode is ${response.statusCode}`), res)
const {features: earthquakes} = JSON.parse(body)
if (response.statusCode !== 200)
return robot.emit('error', new Error(`Response statusCode is ${response.statusCode}`), res)
const { features: earthquakes } = JSON.parse(body)

const earthquakesFilter = earthquakes.filter(({properties: {place}}) => {
const earthquakesFilter = earthquakes.filter(({ properties: { place } }) => {
return country ? new RegExp(country, 'i').test(place) : true
})

Expand All @@ -41,14 +42,18 @@ module.exports = robot => {
}
if (earthquakesFilter.length === 0) {
const text = `Por suerte, ningún temblor mayor a ${minMagnitude} grados en ${country || 'todo el mundo'}.`
options.attachments = [{
fallback: text,
text: text
}]
options.attachments = [
{
fallback: text,
text: text
}
]
return robot.adapter.client.web.chat.postMessage(res.message.room, null, options)
}
options.attachments = earthquakesFilter.map(({properties: {place, mag, time, title, url}}) => {
const fallback = `${title}: \n- Lugar: ${place} \n- Magnitud: ${mag} (richter) \n- Fecha/Hora: ${new Date(time).toString()} \n- Enlace: ${url}`
options.attachments = earthquakesFilter.map(({ properties: { place, mag, time, title, url } }) => {
const fallback = `${title}: \n- Lugar: ${place} \n- Magnitud: ${mag} (richter) \n- Fecha/Hora: ${new Date(
time
).toString()} \n- Enlace: ${url}`
return {
fallback: fallback,
color: '#36a64f',
Expand All @@ -67,7 +72,9 @@ module.exports = robot => {
},
{
title: 'Fecha',
value: new Date(time).toISOString().replace(/(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}).\d+Z/, '$1 $2 UTC'),
value: new Date(time)
.toISOString()
.replace(/(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}).\d+Z/, '$1 $2 UTC'),
short: true
}
]
Expand All @@ -78,9 +85,15 @@ module.exports = robot => {
if (earthquakesFilter.length === 0) {
return res.send(`Por suerte, ningún temblor mayor a ${minMagnitude} grados en ${country || 'todo el mundo'}.`)
}
res.send(earthquakesFilter.map(({properties: {place, mag, time, title, url}}) => {
return `${title}: \n- Lugar: ${place} \n- Magnitud: ${mag} (richter) \n- Fecha/Hora: ${new Date(time).toString()} \n- Enlace: ${url}`
}).join('\n\n'))
res.send(
earthquakesFilter
.map(({ properties: { place, mag, time, title, url } }) => {
return `${title}: \n- Lugar: ${place} \n- Magnitud: ${mag} (richter) \n- Fecha/Hora: ${new Date(
time
).toString()} \n- Enlace: ${url}`
})
.join('\n\n')
)
}
})
})
Expand Down
12 changes: 6 additions & 6 deletions test/portadas.test.js
Expand Up @@ -7,16 +7,16 @@ const nock = require('nock')

const helper = new Helper('../scripts/portadas.js')
const now = new Date()
now.setHours(now.getHours() - 3) // UTC to -03:00
now.setHours(now.getHours() - 4) // UTC to -04:00
const date = now.toISOString().replace(/(\d{2})(\d{2})-(\d+)-(\d+)T\d+:\d+:\d+.\d+Z/, '$4_$3_$2')
const img = `http://impresa.soy-chile.cl/HoyxHoy/210617/hoyxhoy/${date}_pag_03-550-afba7c.jpg`

test.beforeEach(t => {
nock('http://www.hoyxhoy.cl')
.get('/endpoints/for-soy.php')
.query({action: 'get-latest', size: 550})
.reply(200, [{img: img}])
t.context.room = helper.createRoom({httpd: false})
.query({ action: 'get-latest', size: 550 })
.reply(200, [{ img: img }])
t.context.room = helper.createRoom({ httpd: false })
})

test.afterEach(t => t.context.room.destroy())
Expand All @@ -26,7 +26,7 @@ test.cb('Debe entregar la portada de la hoyxhoy', t => {
setTimeout(() => {
t.deepEqual(t.context.room.messages, [
['user', 'hubot portada hoyxhoy'],
['hubot', 'Esta portada es del 21/06/2017'],
['hubot', 'Esta portada es del 21/06/2017'],
['hubot', img]
])
t.end()
Expand All @@ -38,7 +38,7 @@ test.cb('Debe entregar la portada de la hoyxhoy incluso cuando se escribe en may
setTimeout(() => {
t.deepEqual(t.context.room.messages, [
['user', 'hubot portada HoyxHoy'],
['hubot', 'Esta portada es del 21/06/2017'],
['hubot', 'Esta portada es del 21/06/2017'],
['hubot', img]
])
t.end()
Expand Down

0 comments on commit 19fcd98

Please sign in to comment.