Created
April 7, 2015 19:01
-
-
Save radubogdan/f1c9899048bbc79e10f1 to your computer and use it in GitHub Desktop.
facebook birthday thanks giver
This file contains hidden or 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
require 'mechanize' | |
base = 'https://graph.facebook.com/v2.3/' | |
route = 'me/feed?since=06.04.2015' | |
access_token = {'access_token' => ENV['ACCESS_TOKEN']} | |
variations = %w(happy bday birthday mulți multi ani trăiești traiesti) | |
agent = Mechanize.new | |
response = JSON.parse(agent.get(base + route, access_token).body) | |
response["data"].each do |res| | |
msg = res["message"].split.map!{ |s| s.downcase!; s.gsub(/\p{^Alnum}/, ''); } | |
if (msg & variations).count != 0 | |
id = res["id"] | |
like_url = base + id + "/likes" | |
comment_url = base + id + "/comments" | |
file = agent.get(comment_url, access_token) | |
thanks_not_given = JSON.parse(file.body)["data"].find { |hash| hash["message"] == "Thanks!" && hash["from"]["name"] == "Radu Croitoru" }.nil? | |
agent.post(like_url, access_token) | |
agent.post(comment_url, access_token.merge!("message" => "Thanks!")) if thanks_not_given | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Heh, automate all the things :D