orsos 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/orsos/commands/get.rb +37 -4
- data/lib/orsos/version.rb +1 -1
- data/lib/orsos/webdownloader.rb +30 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 366b603819a5784379c68774ac3a0287dd2dc162
|
4
|
+
data.tar.gz: 341c70923d8d8581671fb7ef84b3b96eb4c89f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 800a3742d40ca1cc86cca6be5066ac6557556aa265f3c1d6b7df1d6fd91213f248de131788232c9a9aaa3b452cf22bdc7ff866382dfefebc7f1e6a9bd8e8c2d7
|
7
|
+
data.tar.gz: e79d62229acf16b5316966621e19a978204d3a1d306231fc0ad742078a14c8c211b15630922689cd19cfc49592ad17612406e3aa553348b3fe83e09c8e01a8c9
|
data/Gemfile.lock
CHANGED
data/lib/orsos/commands/get.rb
CHANGED
@@ -4,7 +4,11 @@ require_relative '../webdownloader'
|
|
4
4
|
module Orsos::Commands
|
5
5
|
class Get < Thor
|
6
6
|
desc "transactions FROM [TO]", "Download campaign finance transactions daily between FROM till TO and saves each day to sos_transactions_{%Y%m%d}-{current time stamp}. eg., orsos get transactions 2014-10-01 2014-10-31. TO defaults to today's date"
|
7
|
-
option :verbose, type: :boolean
|
7
|
+
option :verbose, type: :boolean, desc: 'turn on verbose logging of search'
|
8
|
+
option :filer_id, type: :numeric, desc: 'conduct search by filer_id'
|
9
|
+
option :single_file, type: :boolean, desc: 'search and save data in date range as a single file rather than one search per day'
|
10
|
+
option :in2csv, type: :boolean, desc: 'use in2csv to convert downloaded xls to csv'
|
11
|
+
option :xls2csv, type: :boolean, desc: 'use xls2csv to convert downloaded xls to csv'
|
8
12
|
def transactions(from, to=Date.today)
|
9
13
|
from_date = case from
|
10
14
|
when Date
|
@@ -23,10 +27,39 @@ module Orsos::Commands
|
|
23
27
|
else
|
24
28
|
raise 'invalid to date'
|
25
29
|
end
|
26
|
-
|
27
|
-
|
30
|
+
|
31
|
+
trans_opts = options.select{|k,v| ['filer_id'].include?(k) }
|
32
|
+
if options['in2csv']
|
33
|
+
csvbin = 'in2csv'
|
34
|
+
fileext = 'csv'
|
35
|
+
elsif options['xls2csv']
|
36
|
+
csvbin = 'xls2csv'
|
37
|
+
fileext = 'csv'
|
38
|
+
else
|
39
|
+
csvbin = nil
|
40
|
+
fileext = 'xls'
|
41
|
+
end
|
42
|
+
|
43
|
+
if !options['single_file'].nil?
|
44
|
+
filename = "sos_transactions_#{from_date.strftime("%Y%m%d")}-#{to_date.strftime("%Y%m%d")}-#{DateTime.now.strftime("%Y%m%d%H%M%S")}.#{fileext}"
|
28
45
|
Orsos::Webdownloader.new(options[:verbose])
|
29
|
-
.
|
46
|
+
.save_campaign_finance_transactions from_date: from_date,
|
47
|
+
to_date: to_date,
|
48
|
+
filename: filename,
|
49
|
+
csvbin: csvbin,
|
50
|
+
options: trans_opts
|
51
|
+
|
52
|
+
else
|
53
|
+
(from_date..to_date).each do |date|
|
54
|
+
filename = "sos_transactions_#{date.strftime("%Y%m%d")}-#{DateTime.now.strftime("%Y%m%d%H%M%S")}.#{fileext}"
|
55
|
+
|
56
|
+
Orsos::Webdownloader.new(options[:verbose])
|
57
|
+
.save_campaign_finance_transactions from_date: date,
|
58
|
+
to_date: date,
|
59
|
+
filename: filename,
|
60
|
+
csvbin: csvbin,
|
61
|
+
options: trans_opts
|
62
|
+
end
|
30
63
|
end
|
31
64
|
end
|
32
65
|
|
data/lib/orsos/version.rb
CHANGED
data/lib/orsos/webdownloader.rb
CHANGED
@@ -1,31 +1,52 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
require 'logger'
|
3
|
+
require 'mkmf'
|
3
4
|
|
4
5
|
class Orsos::Webdownloader
|
5
6
|
def initialize(verbose=false)
|
6
7
|
@verbose = verbose
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
-
puts "downloading transactions for #{
|
11
|
-
filename = "#{filename_prefix}_#{date.strftime("%Y%m%d")}-#{DateTime.now.strftime("%Y%m%d%H%M%S")}.xls"
|
10
|
+
def save_campaign_finance_transactions from_date:, to_date:, filename: , csvbin:, options: {}
|
11
|
+
puts "downloading transactions for #{from_date.strftime('%Y-%m-%d')} till #{to_date.strftime('%Y-%m-%d')}"
|
12
12
|
|
13
|
-
export_page = download_campaign_finance_transactions
|
13
|
+
export_page = download_campaign_finance_transactions from_date: from_date, to_date: to_date, filer_id: options['filer_id']
|
14
14
|
raise "could not download campaign finance transactions" if export_page.nil?
|
15
|
-
File.open(filename, 'wb') {|f| f.write(export_page.body) } if export_page
|
16
15
|
|
17
|
-
|
16
|
+
if !csvbin.nil?
|
17
|
+
csvpath = find_executable csvbin
|
18
|
+
raise "could not find #{csvbin} in $PATH" if csvpath.nil?
|
19
|
+
file = Tempfile.new(['xls2csv-', '.xls'])
|
20
|
+
file.binmode
|
21
|
+
begin
|
22
|
+
file.write(export_page.body)
|
23
|
+
file.rewind
|
24
|
+
|
25
|
+
data = `#{csvpath} #{file.path}`
|
26
|
+
|
27
|
+
File.open(filename, 'wb') {|f| f.write(data) } if data
|
28
|
+
ensure
|
29
|
+
file.close
|
30
|
+
file.unlink
|
31
|
+
end
|
32
|
+
|
33
|
+
puts "saved transactions for #{from_date.strftime("%Y-%m-%d")} till #{to_date.strftime('%Y-%m-%d')} to #{filename}"
|
34
|
+
else
|
35
|
+
File.open(filename, 'wb') {|f| f.write(export_page.body) } if export_page
|
36
|
+
puts "saved transactions for #{from_date.strftime("%Y-%m-%d")} till #{to_date.strftime('%Y-%m-%d')} to #{filename}"
|
37
|
+
end
|
18
38
|
end
|
19
39
|
|
20
40
|
private
|
21
|
-
def download_campaign_finance_transactions
|
41
|
+
def download_campaign_finance_transactions from_date:, to_date:, filer_id: nil
|
22
42
|
set_agent
|
23
43
|
export_page = nil
|
24
44
|
|
25
45
|
@agent.get("#{@base_url}/orestar/gotoPublicTransactionSearch.do") do |search_page|
|
26
46
|
search_page.form_with(name: 'cneSearchForm') do |form|
|
27
|
-
form.cneSearchTranFiledStartDate =
|
28
|
-
form.cneSearchTranFiledEndDate =
|
47
|
+
form.cneSearchTranFiledStartDate = from_date.strftime("%m/%d/%Y")
|
48
|
+
form.cneSearchTranFiledEndDate = to_date.strftime("%m/%d/%Y")
|
49
|
+
form.cneSearchFilerCommitteeId = filer_id unless filer_id.nil?
|
29
50
|
|
30
51
|
@results_page = @agent.submit(form, form.button_with(value: "Search"))
|
31
52
|
if link = @results_page.link_with(text: "Export To Excel Format")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orsos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Chang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|