Skip to content

Instantly share code, notes, and snippets.

@caffo
Created July 21, 2008 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caffo/456 to your computer and use it in GitHub Desktop.
Save caffo/456 to your computer and use it in GitHub Desktop.
virtua.com.br bandwidth usage reporter (twitter bot)
#!/usr/bin/ruby
# consumobot.rb - virtua.com.br bandwidth usage reporter (twitter bot)
# non-copyright (c) 2008 rodrigo franco <caffo@imap.cc>
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
#
# consumobot.rb - bot que envia informacoes sobre o
# consumo do virtua via twitter
#
# coloque aqui o mac address do seu modem
MAC_ADDRESS = '000000000000'
# configuracao do twitter
# esses dados NAO sao da sua conta no twitter
# crie uma conta nova e coloque os dados aqui.
# alem disso, certifique-se de que a nova conta
# o tem como 'follower' e que voce a
# 'segue' tambem
TWITTER_USER = 'foobar'
TWITTER_PASS = 'foobar'
TWITTER_RCPT = 'me'
# nao toque em nada daqui pra baixo :P
require 'rubygems'
require 'twitter' # twitter4r
require 'mechanize'
TWITTER = Twitter::Client.new(:login => TWITTER_USER, :password => TWITTER_PASS)
module ConsumoBot
def self.retreive
agent = WWW::Mechanize.new
page = agent.post("http://consumo.virtua.com.br/consumo.php",
{
"macadd" => MAC_ADDRESS,
"mes" => "0#{Date.today.month}",
"ano" => "#{Date.today.year.to_s[2..3]}"
}
)
doc = Hpricot(page.body)
cells = doc.search(".onze")
total = cells.last.inner_html
upload = cells[cells.size-3].inner_html
download = cells[cells.size-4].inner_html
total_dia = cells[cells.size-2].inner_html
data = cells[cells.size-5].inner_html
raise Exception.new, "Informacao nao disponivel no site do virtua" if data == "Data"
return "#{data}: #{download}d/#{upload}u (#{total_dia}) [#{total}]"
end
def self.exec
TWITTER.message(:post, retrieve, TWITTER_RCPT)
end
end
ConsumoBot.exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment