Forked from radubogdan/gist:f1c9899048bbc79e10f1
Last active
August 29, 2015 14:18
-
-
Save nightsh/b77e0ca6852c4b4641da to your computer and use it in GitHub Desktop.
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
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