Skip to content

Instantly share code, notes, and snippets.

@tpai
Last active September 11, 2015 18:33
Show Gist options
  • Save tpai/aa6e9dcb00bba17a43bb to your computer and use it in GitHub Desktop.
Save tpai/aa6e9dcb00bba17a43bb to your computer and use it in GitHub Desktop.
hubot script
module.exports = (robot) ->
robot.hear /gog [help|?]/i, (result) ->
result.send "gog [rank|new|bestselling_per_week],[number]"
robot.hear /gog (.*),(.*)/i, (result) ->
sort = result.match[1].trim()
num = result.match[2]
url = "http://www.gog.com/games/ajax/filtered?sort="+sort+"&limit=" + num
robot.http(url)
.header('Accept', 'application/json')
.get() (err, res, body) ->
list = ""
if err
result.send err.toString()
else
data = JSON.parse body
for product in data.products
list += product.title + "\nPrice: $" + product.price.amount + "/$" + product.price.baseAmount + " (" + product.price.discountPercentage + "%)\nhttp://www.gog.com/" + product.url + "\n\n"
result.send list
module.exports = (robot) ->
robot.hear /weather [help|?]/i, (result) ->
result.send "weather [city],[country]"
robot.hear /weather (.*),(.*)/i, (result) ->
city = result.match[1].trim()
country = result.match[2].trim()
url = "http://api.openweathermap.org/data/2.5/forecast/daily?q="+city+"," + country + "&units=metric"
robot.http(url)
.header('Accept', 'application/json')
.get() (err, res, body) ->
if err
result.send err.toString()
else
data = JSON.parse body
if data.cod is "200"
weather = data.city.name+", "+data.city.country+"\n------------\n"
for val in data.list
d = new Date(val.dt * 1000)
pad = "00"
yr = d.getFullYear()
mt = ""+(d.getMonth()+1)
dt = ""+d.getDate()
# pad zero
mt = pad.substring(0, pad.length - mt.length) + mt
dt = pad.substring(0, pad.length - dt.length) + dt
# result
weather += yr + '-' + mt + '-' + dt + ' ' + val.weather[0].main + '(' + val.weather[0].description + ') ' + val.temp.min.toFixed(1) + '°C~' + val.temp.max.toFixed(1) + '°C\n'
result.send weather
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment