rubbish_collection 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -1
- data/lib/rubbish_collection.rb +2 -2
- data/lib/rubbish_collection/rushmoor.rb +45 -0
- data/lib/rubbish_collection/version.rb +1 -1
- metadata +2 -1
data/README.md
CHANGED
@@ -20,7 +20,8 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
address = OpenStruct.new :
|
23
|
+
address = OpenStruct.new :house_number => "2",
|
24
|
+
:street_name => "Beech Road", :postcode => "GU14 8EU"
|
24
25
|
collection_times = RubbishCollection.times_at_address address
|
25
26
|
collection_times.each do |t|
|
26
27
|
puts t.to_s
|
@@ -44,8 +45,19 @@ just the postcode but Westminster need a street name. At some point we should
|
|
44
45
|
either find a gem that already caters to addresses and provides a nice API and
|
45
46
|
tools for comparison, or we should define or own.
|
46
47
|
|
48
|
+
Not all local authorities perform all collections on a weekly basis -
|
49
|
+
[fuzzmonkey][2] points out that Rushmoor only pick up recycling once a
|
50
|
+
fortnight. This project can't handle schedules like that yet. Perhaps we
|
51
|
+
should consider pulling in a more advanced temporal event library?
|
52
|
+
|
53
|
+
* [Recurring Event][3]
|
54
|
+
* [RUNT][4]
|
55
|
+
|
47
56
|
[0]: https://raw.github.com/craigw/local_authority/master/db/local_authorities.csv
|
48
57
|
[1]: https://github.com/craigw/local_authority
|
58
|
+
[2]: https://github.com/fuzzmonkey
|
59
|
+
[3]: https://github.com/nickstenning/recurring_event
|
60
|
+
[4]: https://github.com/texel/runt
|
49
61
|
|
50
62
|
|
51
63
|
## Contributing
|
data/lib/rubbish_collection.rb
CHANGED
@@ -34,7 +34,6 @@ module RubbishCollection
|
|
34
34
|
end
|
35
35
|
|
36
36
|
class CollectionTime
|
37
|
-
DAYS = %w( Sunday Monday Tuesday Wednesday Thursday Friday Saturday ).map(&:freeze).freeze
|
38
37
|
|
39
38
|
attr_accessor :day
|
40
39
|
private :day=, :day
|
@@ -52,7 +51,7 @@ module RubbishCollection
|
|
52
51
|
end
|
53
52
|
|
54
53
|
def human_day
|
55
|
-
|
54
|
+
Date::DAYNAMES[day]
|
56
55
|
end
|
57
56
|
|
58
57
|
def human_time
|
@@ -99,3 +98,4 @@ end
|
|
99
98
|
|
100
99
|
require 'rubbish_collection/redbridge'
|
101
100
|
require 'rubbish_collection/southwark'
|
101
|
+
require 'rubbish_collection/rushmoor'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module RubbishCollection
|
2
|
+
|
3
|
+
class RushmoorAdapter
|
4
|
+
|
5
|
+
def self.load
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'date'
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize local_authority
|
11
|
+
end
|
12
|
+
|
13
|
+
def collection_times_at address
|
14
|
+
Net::HTTP.start "www.rushmoor.gov.uk", 80 do |http|
|
15
|
+
postcode = address.postcode.gsub("\s","") # Rushmoor don't like post codes with spaces
|
16
|
+
req = Net::HTTP::Get.new "/article/1589/Address-search?housenumber=#{address.house_number}&addressdetail=#{postcode}"
|
17
|
+
response = http.request req
|
18
|
+
if response.code == "302"
|
19
|
+
response = Net::HTTP.get_response(URI.parse(response.header['location']))
|
20
|
+
end
|
21
|
+
doc = Nokogiri::HTML response.body
|
22
|
+
info = doc.xpath("//*[@id='inmyarea']")
|
23
|
+
container = info.xpath("//*[@class='ima_block']").first
|
24
|
+
times = []
|
25
|
+
container.xpath("p").each do |rubbish_div|
|
26
|
+
lines = rubbish_div.text.split("\n")
|
27
|
+
collection_type = case lines[1]
|
28
|
+
when /rubbish bin collection/
|
29
|
+
:domestic_refuse
|
30
|
+
# In Rushmoor, recycling comes every two weeks, CollectionTime doesn't really support this
|
31
|
+
# when /recycling collection/
|
32
|
+
# :domestic_recycling
|
33
|
+
else
|
34
|
+
next
|
35
|
+
end
|
36
|
+
day_index = Date::DAYNAMES.index(lines[2].strip.split(" ")[0])
|
37
|
+
times << CollectionTime.new(day_index, :unknown, collection_type)
|
38
|
+
end
|
39
|
+
times
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RubbishCollection.register_adapter 'http://mapit.mysociety.org/area/2337', RubbishCollection::RushmoorAdapter
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubbish_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- Rakefile
|
58
58
|
- lib/rubbish_collection.rb
|
59
59
|
- lib/rubbish_collection/redbridge.rb
|
60
|
+
- lib/rubbish_collection/rushmoor.rb
|
60
61
|
- lib/rubbish_collection/southwark.rb
|
61
62
|
- lib/rubbish_collection/version.rb
|
62
63
|
- rubbish_collection.gemspec
|