Display the daily meal of Mamacake (ie. https://www.facebook.com/MamaCake.Paris - MamaCake Paris - Restaurant sans gluten).
Last active
August 28, 2015 13:59
-
-
Save Remiii/94dc6bb9567a8a63fe24 to your computer and use it in GitHub Desktop.
Hubot MamaCake (Paris 18e)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# "facebook grabber." | |
# | |
# Dependencies: | |
# None | |
# | |
# Configuration: | |
# None | |
# | |
# Commands: | |
# hubot show [me] mamacake - Display the daily meal of Mamacake | |
# | |
# Notes: | |
# Show Daily Meal of Mamacake (Paris 18e) | |
# | |
# Author: | |
# Adam Tahri (aka gotakk) | |
module.exports = (robot) -> | |
robot.hear /show( me)? mamacake/i, (response) -> | |
robot.http("https://graph.facebook.com/oauth/access_token?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=client_credentials") | |
.get() (err, res, body) -> | |
tab = body.split '=' | |
access_token = tab[1] | |
robot.http("https://graph.facebook.com/v2.4/542218599184696/posts?fields=full_picture,message,created_time&access_token=" + access_token) | |
.get() (err, res, body) -> | |
data = JSON.parse body | |
datetime = new Date(data.data[0]["created_time"]) | |
today = new Date() | |
if datetime.getDay() is today.getDay() | |
response.send data.data[0]["full_picture"] | |
else | |
response.send "No meal was posted yet" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment