Bart's Snippets

Scrape Bill text files

scrape_bill_text.rb
require 'open-uri'
require 'nokogiri'
require 'mechanize'

def get_bill_nums
  doc = Nokogiri::HTML(open("http://leg.colorado.gov/bill-search"))
  bill_nums = doc.css("div.field-name-field-bill-number div.field-items").text.split("\s")
  bill_nums
end

bill_nums = get_bill_nums()
puts bill_nums
bill_nums.each do |bill_num|
  agent = Mechanize.new
  doc = Nokogiri::HTML(open("http://leg.colorado.gov/bills/#{bill_num}"))
  bill_file_url = doc.css("div.recent-bill-text a")[0].attributes["href"].text
  if !File.exists? "files/bills/#{bill_num}.pdf"
    agent.get(bill_file_url).save "files/bills/#{bill_num}.pdf"
  end
end

an Elixir module to archive pages

archiver.ex
defmodule Archiver do                                                                                           
  def archive(url, user_id, bookmark_id) do                                                                                                       
    summary = Readability.summarize(url)                                                                                                          
    page = summary.article_html                                                                                                                   
    path = "priv/static/archive/#{user_id}"                                                                                                       
    unless File.exists?(path) do                                                                                                                  
      File.mkdir(path)                                                                                                                            
    end                                                                                                                                           
    File.write("#{path}/#{bookmark_id}.html", page)                                                                                               
  end                                                                                                                                             
end   

Hello Bigwig 2 written in Elixir

hello.ex
defmodule Hello do
  def bigwig do 
    IO.puts "Hello Bigwig!"
    IO.puts "That is all."
  end
end