Last active
December 14, 2015 07:28
-
-
Save andersonvom/5050287 to your computer and use it in GitHub Desktop.
Monitor Correios (correios.com.br) website for update on shipping information.
Set up FROM_EMAIL and TO_EMAIL and just put it in your crontab or do a while;true bash loop: $ ruby correios.rb <TRACKING_ID>
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
#!/usr/bin/ruby | |
require 'mail' | |
GMAIL_USERNAME = "username" | |
GMAIL_PASSWORD = "password" | |
options = { :address => "smtp.gmail.com", | |
:port => 587, | |
:domain => 'gmail.com', | |
:user_name => GMAIL_USERNAME, | |
:password => GMAIL_PASSWORD, | |
:authentication => 'plain', | |
:enable_starttls_auto => true } | |
Mail.defaults do | |
delivery_method :smtp, options | |
end |
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 'fileutils' | |
require './config.rb' # Put your Mail configuration here (e.g. localhost, gmail, etc) | |
FROM_EMAIL = "[email protected]" | |
TO_EMAIL = "[email protected]" | |
def mail(from_email, to_email, content) | |
Mail.deliver do | |
from from_email | |
to to_email | |
subject 'Correios: Atualizacao!' | |
body content | |
end | |
end | |
SHIPPING_ID = ARGV[0] | |
TRACKING_URL = "http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=002&P_TIPO=002&P_COD_LIS=#{SHIPPING_ID}" | |
current_version = "correios-current.html" | |
last_version = "correios-last.html" | |
# This is where magic happens! | |
print "Checking for update... " | |
FileUtils.touch current_version | |
FileUtils.touch last_version | |
`wget -qO #{current_version} '#{TRACKING_URL}'` | |
diff = `diff #{current_version} #{last_version}` | |
unless diff.empty? | |
print "Found! Sending mail... " | |
mail(FROM_EMAIL, TO_EMAIL, TRACKING_URL) | |
end | |
`mv #{current_version} #{last_version}` | |
puts "[ OK ]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment