Skip to content

Commit

Permalink
add patch files temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
baob committed Sep 14, 2011
0 parents commit ba34fa6
Show file tree
Hide file tree
Showing 4 changed files with 1,273 additions and 0 deletions.
245 changes: 245 additions & 0 deletions patch1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
From d137e5834a3fa3b2cde53f581ace8d57245311bc Mon Sep 17 00:00:00 2001
From: baob <coder@onesandthrees.com>
Date: Fri, 10 Dec 2010 00:25:15 +0000
Subject: first cut - working, no specs

---
app/models/openlylocal/council.rb | 55 +++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
create mode 100644 app/models/openlylocal/council.rb

diff --git a/app/models/openlylocal/council.rb b/app/models/openlylocal/council.rb
new file mode 100644
index 0000000..a23b575
--- /dev/null
+++ b/app/models/openlylocal/council.rb
@@ -0,0 +1,55 @@
+module Openlylocal
+
+ require 'rexml/document'
+ require 'net/http'
+ require 'uri'
+
+ class Council
+
+ attr_accessor :xml_data, :name, :openlylocal_url, :wikipedia_url, :address
+
+ def initialize(council_node)
+ self.xml_data = council_node
+ self.name = council_node.elements['name'].text
+ self.openlylocal_url = council_node.elements['openlylocal-url'].text
+ self.wikipedia_url = council_node.elements['wikipedia-url'].text
+ self.address = council_node.elements['address'].text
+ self
+ end
+
+ filename = File.expand_path(File.dirname(__FILE__) + "/../../../files/openlylocal_councils.xml")
+
+ puts "------------"+filename
+
+ begin
+ file = File.new(filename)
+ rescue Errno::ENOENT
+ puts "------------ get "
+
+ url = URI.parse('http://openlylocal.com/councils.xml')
+ req = Net::HTTP::Get.new(url.path)
+ res = Net::HTTP.start(url.host, url.port) {|http|
+ http.request(req)
+ }
+
+ puts "------------ get 2"
+
+ File.open(filename, 'w') {|f| f.write(res.body) }
+ puts "------------ get 3 "
+
+ file = File.new(filename)
+
+ end
+
+ council_doc = REXML::Document.new(file)
+ @@councils = council_doc.root.elements.map do |council_node|
+ Council.new(council_node)
+ end
+
+
+ def self.find(name)
+ @@councils.detect{ |c| c.name == name }
+ end
+ end
+
+end
\ No newline at end of file
--
1.7.6


From 5c6980c3546e167acfd05fda1c532300c91dc58b Mon Sep 17 00:00:00 2001
From: baob <coder@onesandthrees.com>
Date: Fri, 10 Dec 2010 01:08:32 +0000
Subject: refinements, no specs

---
app/models/openlylocal/council.rb | 58 +++++++++++++++++++++++-------------
1 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/app/models/openlylocal/council.rb b/app/models/openlylocal/council.rb
index a23b575..8a41275 100644
--- a/app/models/openlylocal/council.rb
+++ b/app/models/openlylocal/council.rb
@@ -6,7 +6,11 @@ module Openlylocal

class Council

- attr_accessor :xml_data, :name, :openlylocal_url, :wikipedia_url, :address
+ attr_accessor :xml_data, :id, :name, :openlylocal_url, :wikipedia_url, :address, :normalised_title, :url,
+ :telephone, :country, :region
+
+ OL_FILENAME = File.expand_path(File.dirname(__FILE__) + "/../../../files/openlylocal_councils.xml")
+ OL_COUNCILS_URL = "http://openlylocal.com/councils.xml"

def initialize(council_node)
self.xml_data = council_node
@@ -14,31 +18,29 @@ module Openlylocal
self.openlylocal_url = council_node.elements['openlylocal-url'].text
self.wikipedia_url = council_node.elements['wikipedia-url'].text
self.address = council_node.elements['address'].text
+ self.id = council_node.elements['id'].text
+ self.normalised_title = council_node.elements['normalised-title'].text
+ self.url = council_node.elements['url'].text
+ self.telephone = council_node.elements['telephone'].text
+ self.country = council_node.elements['country'].text
+ self.region = council_node.elements['region'].text
self
end

- filename = File.expand_path(File.dirname(__FILE__) + "/../../../files/openlylocal_councils.xml")
-
- puts "------------"+filename
-
- begin
- file = File.new(filename)
- rescue Errno::ENOENT
- puts "------------ get "
-
- url = URI.parse('http://openlylocal.com/councils.xml')
+ def self.fetch_file
+ url = URI.parse(OL_COUNCILS_URL)
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
-
- puts "------------ get 2"
-
- File.open(filename, 'w') {|f| f.write(res.body) }
- puts "------------ get 3 "
-
- file = File.new(filename)
-
+ File.open(OL_FILENAME, 'w') {|f| f.write(res.body) }
+ end
+
+ begin
+ file = File.new(OL_FILENAME)
+ rescue Errno::ENOENT
+ fetch_file
+ file = File.new(OL_FILENAME)
end

council_doc = REXML::Document.new(file)
@@ -47,9 +49,23 @@ module Openlylocal
end


- def self.find(name)
+ def self.find_by_name(name)
@@councils.detect{ |c| c.name == name }
end
- end
+
+ def self.find(id) # find on openly local's own id, takes string or integer
+ match_id = id.is_a?(Fixnum) ? id.to_s : id
+ @@councils.detect{ |c| c.id == match_id }
+ end
+
+ def self.all
+ @@councils
+ end
+
+ def self.count
+ @@councils.size
+ end
+
+ end # class Council

end
\ No newline at end of file
--
1.7.6


From e3ed29ac2a67ac82ad7c6cea8ef3451eb7b42c7b Mon Sep 17 00:00:00 2001
From: baob <coder@onesandthrees.com>
Date: Fri, 10 Dec 2010 10:28:47 +0000
Subject: better url, more orgs, but slower load

---
app/models/openlylocal/council.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/models/openlylocal/council.rb b/app/models/openlylocal/council.rb
index 8a41275..8d6dbd8 100644
--- a/app/models/openlylocal/council.rb
+++ b/app/models/openlylocal/council.rb
@@ -10,7 +10,7 @@ module Openlylocal
:telephone, :country, :region

OL_FILENAME = File.expand_path(File.dirname(__FILE__) + "/../../../files/openlylocal_councils.xml")
- OL_COUNCILS_URL = "http://openlylocal.com/councils.xml"
+ OL_COUNCILS_URL = "http://openlylocal.com/councils/open.xml"

def initialize(council_node)
self.xml_data = council_node
@@ -68,4 +68,4 @@ module Openlylocal

end # class Council

-end
\ No newline at end of file
+end
--
1.7.6


From b2c3bad3f884ce6e3e34992800218a168ca35ccc Mon Sep 17 00:00:00 2001
From: baob <coder@onesandthrees.com>
Date: Fri, 10 Dec 2010 11:21:46 +0000
Subject: note: not production-ready

---
app/models/openlylocal/council.rb | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/app/models/openlylocal/council.rb b/app/models/openlylocal/council.rb
index 8d6dbd8..d1c3d6e 100644
--- a/app/models/openlylocal/council.rb
+++ b/app/models/openlylocal/council.rb
@@ -5,6 +5,14 @@ module Openlylocal
require 'uri'

class Council
+
+ # NOTE NOTE NOTE ----- This is not production ready code
+ # 1) Needs lazy loading of URL (I think)
+ # 2) Needs memcaching
+ # 3) Needs either elimination of file or else managing when file goes stale
+ # 4) Protection against HTTP problems, such as 404, server not responsding, short data file
+ # 5) protection against XML parsing errors
+ # 6) Probably more ...

attr_accessor :xml_data, :id, :name, :openlylocal_url, :wikipedia_url, :address, :normalised_title, :url,
:telephone, :country, :region
--
1.7.6

Loading

0 comments on commit ba34fa6

Please sign in to comment.