Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#!/usr/bin/ruby # Copyright (c) 2007 Rodrigo Franco <caffo@imap.cc> # Property: Flexcode - http://flexcode.com.br/ # # 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
This paste will be private.
From the Design Piracy series on my blog: