jackowayed-state-reps 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/reps-main.rb +14 -0
  2. data/lib/person.rb +63 -0
  3. data/lib/state-reps.rb +176 -0
  4. metadata +55 -0
data/bin/reps-main.rb ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'statereps'
4
+ include StateReps
5
+
6
+
7
+ peoplestr = (File.readlines ARGV[0])
8
+ people = peoplestr.map{|x|
9
+ p = Person.new
10
+ p.readIn(x)
11
+ p
12
+ }
13
+
14
+ getReps(people)
data/lib/person.rb ADDED
@@ -0,0 +1,63 @@
1
+ class Person
2
+ attr_accessor :name, :address, :city, :state, :zip9, :sd, :rd
3
+
4
+ @name = ""
5
+ @address = ""
6
+ @city = ""
7
+ @state = ""
8
+ @zip9 = ""
9
+ @sd = ""
10
+ @rd = ""
11
+
12
+ def readIn(str)
13
+ arr=str.chomp.split("\t")
14
+ @name = arr[0].to_s.chomp
15
+ @address = arr[1].to_s.chomp
16
+ @city = arr[2].to_s.chomp
17
+ @state = arr[3].to_s.chomp
18
+ @zip9 = arr[4].to_s.chomp
19
+ @SD = arr[5].to_s.chomp
20
+ @RD = arr[6].to_s.chomp
21
+ end
22
+
23
+ def writeOut()
24
+ str = ""
25
+ if (@name)
26
+ str+=@name
27
+ str+="\t"
28
+ end
29
+ if (@address)
30
+ str+=@address
31
+ str+="\t"
32
+ end
33
+ if (@city)
34
+ str+=@city
35
+ str+="\t"
36
+ end
37
+ if (@state)
38
+ str+=@state
39
+ str+="\t"
40
+ end
41
+ if (@zip9)
42
+ str+=@zip9
43
+ str+="\t"
44
+ end
45
+ if (@sd)
46
+ str+=@sd
47
+ str+="\t"
48
+ end
49
+ if (@rd)
50
+ str+=@rd
51
+ end
52
+ return str.chomp;
53
+ end
54
+ def to_s
55
+ self.writeOut
56
+ end
57
+ def set_reps
58
+ r = reps self
59
+ self.rd = r[:rd]
60
+ self.sd = r[:sd]
61
+ r
62
+ end
63
+ end
data/lib/state-reps.rb ADDED
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module StateReps
4
+ require 'person'
5
+ require 'net/http'
6
+ require 'uri'
7
+ def spacesToPlus(str)
8
+ str = str.to_s
9
+ arr = str.split(" ")
10
+ str = ""
11
+ arr.each{|x|
12
+ str+=x
13
+ str+="+"
14
+ }
15
+ str = str[0,str.length-1] if str.include?("+")
16
+ return str
17
+ end
18
+
19
+ def spacesToHTML(str)
20
+ str = str.to_s
21
+ arr = str.split(" ")
22
+ str = ""
23
+ arr.each{|x|
24
+ str+=x
25
+ str+=" "
26
+ }
27
+ str = str[0,str.length-1] if str.include?("+")
28
+ return str
29
+ end
30
+
31
+
32
+
33
+
34
+ #format for files: Name \t Address \t City \t State \t Zip9 \t SD \t RD
35
+
36
+ def putPeople(people)
37
+ out = File.new("uufn2.txt", "w")
38
+ people.each{|x|
39
+ str = ""
40
+ str<< x.name if x.name
41
+ str<< "\t"
42
+ str<< x.address if x.address
43
+ str<< "\t"
44
+ str<< x.city if x.city
45
+ str<< "\t"
46
+ str<< x.state if x.state
47
+ str<< "\t"
48
+ str<< x.zip9 if x.zip9
49
+ str<< "\t"
50
+ str<< x.sd if x.sd
51
+ str<< "\t"
52
+ str<< x.rd if x.rd
53
+ out<< str
54
+ out<< "\n"
55
+ }
56
+ out.close
57
+ end
58
+
59
+
60
+ def zip_9(person)
61
+ begin
62
+ url = URI.parse("http://zip4.usps.com/zip4/zcl_0_results.jsp?visited=1&pagenumber=0&firmname=&address2=#{spacesToPlus(person.address).upcase}&address1=&city=#{spacesToPlus(person.city).upcase}&state=#{spacesToPlus(person.state).upcase}&urbanization=&zip5=&submit.x=0&submit.y=0&submit=Find+ZIP+Code")
63
+ #puts url
64
+ response = Net::HTTP.get(url)
65
+
66
+ page = response.to_s
67
+ page = page[32000..-1]
68
+ #puts page
69
+ #regex = /#{spacesToHTML(person.city)}&nbsp;#{spacesToHTML(person.state)}&nbsp;\d\d\d\d\d-\d\d\d\d/i
70
+ regex = /\d\d\d\d\d-\d\d\d\d/
71
+ #regex = /Newark&nbsp;DE&nbsp;&nbsp;19711-2334/i
72
+ #regex = /<br \/>/
73
+ #puts regex
74
+ #zipspot = (/#{spacesToHTML(person.address).upcase}#{spacesToHTML(person.city)}&nbsp;#{spacesToHTML(x.state)}&nbsp;\d\d\d\d\d-\d\d\d\d/ =~ page)
75
+ zipspot = regex=~page
76
+ zip = page[zipspot,10] if (zipspot)
77
+ #puts zip
78
+ zip
79
+ rescue
80
+ puts $!
81
+ puts person.name
82
+ end
83
+ end
84
+
85
+ def getZip9()
86
+
87
+ #POST = "digg.com"
88
+ #PORT = 80
89
+
90
+
91
+
92
+ #Net::HTTP.start(HOST, PORT) do |http|
93
+ people.each{|x|
94
+ # x = Person.new
95
+ # x.address="112 Great Circle Rd"
96
+ # x.city="Newark"
97
+ # x.state="DE"
98
+
99
+
100
+ #request = Net::HTTP::Post.new(URI2,{"address1"=> x.address, "city"=> x.city, "state"=> x.state})
101
+ # request = Net::HTTP::Post.new(URI2, {"address2" => "112+Great+Circle+Rd", "city" => "Newark", "state" => "DE", "address1" => "", "zip5" => "", "visited" => "1", "pagenumber" => "0", "firmname"=>"", "urbanization" => "", "submit.x" => "0", "sumbit.y" => "0", "submit" => "Find+ZIP+Code"})
102
+
103
+
104
+
105
+ # uri2 = "/zip4/zcl_0_results.jsp?visited=1&pagenumber=0&firmname=&address2=#{spacesToPlus(x.address).upcase}&address1=&city=#{spacesToPlus(x.city).upcase}&state=#{spacesToPlus(x.state).upcase}&urbanization=&zip5=&submit.x=0&submit.y=0&submit=Find+ZIP+Code"
106
+ # request = Net::HTTP::Get.new(uri2)
107
+ # response = http.request(request)
108
+ #response = Net::HTTP.get(URI.parse("zip4.usps.com/zip4/zcl_0_results.jsp?visited=1&pagenumber=0&firmname=&address2=#{spacesToPlus(x.address).upcase}&address1=&city=#{spacesToPlus(x.city).upcase}&state=#{spacesToPlus(x.state).upcase}&urbanization=&zip5=&submit.x=0&submit.y=0&submit=Find+ZIP+Code"))
109
+
110
+
111
+
112
+ #page = Net::HTTP.post_form(URI.parse("zip4.usps.com/zip4/zcl_0_results.jsp"), {"address1"=> x.address, "city"=> x.city, "state"=> x.state})
113
+ #uri2 = "/zip4/zcl_0_results.jsp?visited=1&pagenumber=0&firmname=&address2=#{spacesToPlus(x.address).upcase}&address1=&city=#{spacesToPlus(x.city).upcase}&state=#{spacesToPlus(x.state).upcase}&urbanization=&zip5=&submit.x=0&submit.y=0&submit=Find+ZIP+Code"
114
+ #uri2 = "/popular/24hours"
115
+
116
+ zip = zip_9 x
117
+ x.zip9 = zip if zip
118
+
119
+ #thanks to http://snakesgemscoffee.blogspot.com/2007/03/twittering-around.html
120
+ }
121
+ #end
122
+
123
+ # peoplestr = ""
124
+ # people.each{|x|
125
+ # peoplestr << x.writeOut()
126
+ # peoplestr << "\n"
127
+ # }
128
+ #puts peoplestr
129
+
130
+ putPeople()
131
+
132
+
133
+ end
134
+
135
+
136
+
137
+ def getReps(people)
138
+ count = 0
139
+ people.each{|x|
140
+ # x = Person.new
141
+ # x.zip9 = "19711-2334"
142
+ x.set_reps
143
+ }
144
+ # puts x.sd
145
+ # puts x.rd
146
+ putPeople(people)
147
+
148
+ end
149
+
150
+
151
+ def reps(person)
152
+ begin
153
+ url = URI.parse("http://www.votesmart.org/search.php?search=#{person.zip9}")
154
+ response = Net::HTTP.get(url);
155
+ spot = /State House/ =~ response
156
+ # puts spot
157
+ response = response[spot..-1] if spot
158
+ regex = /\d+/
159
+ regex =~ response
160
+ reps = {}
161
+ #person.rd = $& if spot
162
+ reps[:rd] = $& if spot
163
+ spot = /State Senate/ =~response
164
+ response = response[spot..-1] if spot
165
+ regex =~ response
166
+ reps[:sd] = $& if spot
167
+ #person.sd = $& if spot
168
+ #puts count += 1
169
+ reps
170
+ rescue
171
+ puts $!
172
+ puts person.name
173
+ { :rd => 'fail', :sd => 'fail' }
174
+ end
175
+ end
176
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jackowayed-state-reps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Jackoway
8
+ autorequire: name
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jackowayed@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin/reps-main.rb
26
+ - lib/person.rb
27
+ - lib/state-reps.rb
28
+ has_rdoc: true
29
+ homepage: http://github.com/jackowayed/state-reps/
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.2.0
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: Determines person's state senate and representative districts. Setup for Delaware, but may work on other states
54
+ test_files: []
55
+