GithubHelp home page GithubHelp logo

go_verbal's Introduction

go_verbal

Ruby access to the congressional record text https://www.gpo.gov/fdsys/browse/collection.action?collectionCode=CREC

download URL collection to local YAML files

Download 2017

require_relative 'lib/go_verbal'

index = GoVerbal.build_index

puts(Time.now)
record = GoVerbal.congressional_record
counter = 0

(2017..2017).each do |y|
  new_dir = "text_files/#{y}"
  Dir.mkdir new_dir
  record.download(directory: new_dir, year: y) do |dl|
    # sleep(1)
    if ((counter  += 1) % 1000 == 10)
      puts(dl)
      puts(Time.now)
    end
  end

  puts(Time.now)
end

download URL collection to local YAML files

Load

Database Setup

Run migrations

sequel -m db/migrations sqlite://dev.db

Reset

sequel -m db/migrations -M 0 sqlite://dev.db

Transfer YAML to DB

DB = Sequel.sqlite('dev.db')

def each_yaml_file
  (2017..2017).each do |y|
    dir = "text_files/#{y}"
    Dir.glob("#{dir}/*.yml") do |file|
      yield Psych.load_file(file)
    end
  end
end

enum = to_enum(:each_yaml_file)

next_enum = enum.next

counter = 0

while next_enum do
  if (counter % 10000) == 0
    puts(next_enum)
    puts(Time.now)
  end
  begin
    DB[:pages].insert(next_enum)
  rescue Sequel::UniqueConstraintViolation
    puts(next_enum.to_s + "already inserted")
  end
  next_enum = enum.next
  counter += 1
end

Populate DB with content

DB = Sequel.sqlite('dev.db')
browser = GoVerbal::GPOSiteBrowser.new

counter = 0

DB[:pages].where("content is null").each do |page|
  if (counter % 1000) == 0
    puts(Time.now)
    puts(page[:date])
  end

  id = page[:id]
  url = page[:url]

  page = browser.go_to(url)
  content = page.body

  DB[:pages].where(:id => id).update(content: content)
  counter += 1
end

go_verbal's People

Contributors

alexilliamson avatar

Watchers

 avatar  avatar

go_verbal's Issues

PG Database

Pages should download straight into pg database

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.