Skip to content

Instantly share code, notes, and snippets.

@radubogdan
Created April 7, 2015 19:01
Show Gist options
  • Save radubogdan/f1c9899048bbc79e10f1 to your computer and use it in GitHub Desktop.
Save radubogdan/f1c9899048bbc79e10f1 to your computer and use it in GitHub Desktop.
facebook birthday thanks giver
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
@rud
Copy link

rud commented Jan 22, 2016

Heh, automate all the things :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment