Skip to content

Instantly share code, notes, and snippets.

@mhfs
Last active August 29, 2015 14:15
Show Gist options
  • Save mhfs/020df44f24e13b2429c6 to your computer and use it in GitHub Desktop.
Save mhfs/020df44f24e13b2429c6 to your computer and use it in GitHub Desktop.
check twitter username availability
require "rubygems"
require "bundler/setup"
require "pony"
require "httparty"
Pony.options = {
:via => :smtp,
:via_options => {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
}
expected = '{"valid":false,"reason":"","msg":"","desc":""}'
endpoint = "https://twitter.com/users/username_available?username=#{ENV['USERNAME']}"
res = HTTParty.get endpoint
if res.response.code == "200" && expected != res.body
puts "changed, sending email"
Pony.mail(
to: ENV["MAIL_TO"],
from: ENV["MAIL_FROM"],
subject: "@#{ENV['USERNAME']} twitter account changed!",
body: "Hurry up! \n\n\n #{res.body}"
)
else
puts "nope #{res.response.code}"
end
#!/bin/bash
# to run out of cron every 10 minutes
# */10 * * * * USERNAME=<HERE> /bin/bash -l -c '/home/deployer/apps/twitter_checker/checker.sh >> /home/deployer/apps/twitter_checker/checker.log'
# might be different depending on the status of the user you're watching
EXPECTED='{"valid":false,"reason":"","msg":"","desc":""}'
RES=$(curl -s https://twitter.com/users/username_available\?username\=$USERNAME)
if [ "$RES" != "$EXPECTED" ]; then
echo "$(date) changed!"
$(echo "$(date) $RES" | mail -s "@$USERNAME twitter account changed!" user@domain.com)
else
echo "$(date) meh"
fi
# A sample Gemfile
source "https://rubygems.org"
ruby "2.1.2"
gem "httparty"
gem "pony"
GEM
remote: https://rubygems.org/
specs:
httparty (0.13.3)
json (~> 1.8)
multi_xml (>= 0.5.2)
json (1.8.2)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
multi_xml (0.5.5)
pony (1.11)
mail (>= 2.0)
PLATFORMS
ruby
DEPENDENCIES
httparty
pony
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment