geonames_local 3.1.3 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c076a06bf13c93cdc9f86aa0a7b215f92fc148b
4
- data.tar.gz: 01481b044838b7b3cde40de3ff0103ad7c932771
3
+ metadata.gz: fdef4304a7290c1a586d7e9b437153021bbc6b37
4
+ data.tar.gz: 41eb2353c1e671d5e6986922221aed29563eb5d5
5
5
  SHA512:
6
- metadata.gz: 76f0ce5d8302588eedf7b05b25f2e1868169dc138c74e9618c8e16efe98a00f24bf085bfa8db0a049d4d1fe2cfa846c1981df5bcb58bf513f85f11c4919bbc64
7
- data.tar.gz: df126c44103aaa93d2e20197c053894de6778622220f5031c2f399766342cd9351d27273a5d379ea98d4ed863daf011d219cc26636368f0f29ed4e10af360a37
6
+ metadata.gz: 01b20afbb5e96032c2882dde15dbc7025e77bd39a50884b6f54f4bf8acc4981273e715eeb472f39cf1db1f4d0c437f8dad4c07640d4506f10042d9024c643ed7
7
+ data.tar.gz: 5f194b2ddc720aa9fdaeb6ef3fd155c52933dba1bd3b9abda4a3c48fca37af590e398144a0e515f13c69112656468f60855b397f64f87bc663fd3cb34e51d98f
@@ -1,11 +1,13 @@
1
- = Geonames Local
1
+ Geonames Local
2
+ ==============
2
3
 
3
4
  Downloads and store Geonames.org data locally (MongoDB, Mongoid).
4
5
  Making every Geoname API operation possible on your servers.
5
6
  No hit limit, fast as possible.
6
7
 
7
8
 
8
- == Usage
9
+ Use
10
+ ---
9
11
 
10
12
  Install where you want to populate the DB:
11
13
 
@@ -18,13 +20,13 @@ You will also need in your system:
18
20
  * curl
19
21
 
20
22
 
21
- === Config YML
22
-
23
+ Config
24
+ ------
23
25
 
24
26
  Create a config yml file:
25
27
 
26
28
 
27
- geonames conf
29
+ geonames init
28
30
 
29
31
 
30
32
  Will generate a "geonames.yml" file on your folder.
@@ -43,7 +45,8 @@ To populate the nations database for the first time use:
43
45
  geonames -c geoconfig.yml nations
44
46
 
45
47
 
46
- == Mongoid
48
+ Adapters
49
+ --------
47
50
 
48
51
  So, supposing Mongoid, something like this is possible:
49
52
 
@@ -59,24 +62,7 @@ Be sure to use a database based on the PostGIS template.
59
62
 
60
63
 
61
64
 
62
- == TODO/Problems
65
+ Next
66
+ ----
63
67
 
64
- - Local relational mapping of geonames data
65
- - Map geonames fields to your db scheme
66
- - Countries are a static yml file :/
67
68
  - IP Geonames? http://ipinfodb.com
68
-
69
-
70
- == Note on Patches/Pull Requests
71
-
72
- * Fork the project.
73
- * Make your feature addition or bug fix.
74
- * Add tests for it. This is important so I don't break it in a
75
- future version unintentionally.
76
- * Commit, do not mess with rakefile, version, or history.
77
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
78
- * Send me a pull request. Bonus points for topic branches.
79
-
80
- == Copyright
81
-
82
- Copyright (c) 2009 Marcos Piccinini. See LICENSE for details.
@@ -19,21 +19,22 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
  gem.summary = %q{Dumps geonames data for local usage}
21
21
 
22
+
22
23
  gem.extra_rdoc_files = [
23
24
  "MIT-LICENSE",
24
- "README.rdoc"
25
+ "README.md"
25
26
  ]
26
27
 
28
+ gem.add_dependency('mongoid', ['>= 3.0.0'])
29
+ gem.add_dependency('geopolitical', ['>= 0.8.0'])
30
+
27
31
  gem.post_install_message = %q{
28
32
  Geonames Local
29
33
  --------------
30
34
 
31
- To use the adapter, install the corresponding gem:
32
-
33
- PostgreSQL => pg
34
- MongoDB => mongoid (optional: mongo_ext)
35
- Tokyo => tokyocabinet
35
+ Use `geonames init` to create a config.yml file.
36
+ Or `geonames -c config.yml` to run using a config file.
36
37
 
37
- Have fun because:
38
+ Have fun!
38
39
  }
39
40
  end
@@ -71,123 +71,128 @@ module Geonames
71
71
  exit
72
72
  end
73
73
 
74
- # Ugly but works?
75
- def work(argv)
76
- trap(:INT) { stop! }
77
- trap(:TERM) { stop! }
78
- Opt.merge! parse_options(argv)
79
- if Opt[:locales].nil? || Opt[:locales].empty?
80
- Opt[:locales] = ['en']
81
- end
82
-
83
- load_config
74
+ # Ugly but works?
75
+ def work(argv)
76
+ trap(:INT) { stop! }
77
+ trap(:TERM) { stop! }
78
+ Opt.merge! parse_options(argv)
79
+ if Opt[:locales].nil? || Opt[:locales].empty?
80
+ Opt[:locales] = ['en']
81
+ end
84
82
 
85
- if shp = Opt[:shp]
86
- SHP.import(shp)
87
- exit
88
- end
83
+ if shp = Opt[:shp]
84
+ SHP.import(shp)
85
+ exit
86
+ end
89
87
 
90
- #
91
- # Return Codes and Exit
92
- #
93
- if argv[0] =~ /list|codes/
94
- Codes.each do |key,val|
95
- str = [val.values, key.to_s].join(" ").downcase
96
- if s = argv[1]
97
- next unless str =~ /#{s.downcase}/
88
+ #
89
+ # Return Codes and Exit
90
+ #
91
+ if argv[0] =~ /list|codes/
92
+ Codes.each do |key,val|
93
+ str = [val.values, key.to_s].join(" ").downcase
94
+ if s = argv[1]
95
+ next unless str =~ /#{s.downcase}/
96
+ end
97
+ puts "#{val[:en_us]}: #{key}"
98
98
  end
99
- puts "#{val[:en_us]}: #{key}"
99
+ exit
100
100
  end
101
- exit
102
- end
103
101
 
104
- #
105
- # If arguments scaffold, config, write down yml.
106
- #
107
- if argv[0] =~ /scaff|conf/
108
- fname = (argv[1] || "geonames") + ".yml"
109
- if File.exist?(fname)
110
- puts "File exists."
111
- else
112
- puts "Writing to #{fname}"
113
- `cp #{File.join(File.dirname(__FILE__), 'config', 'geonames.yml')} #{fname}`
102
+ #
103
+ # If arguments scaffold, config, write down yml.
104
+ #
105
+ if argv[0] =~ /scaff|conf|init/
106
+ fname = (argv[1] || "geonames") + ".yml"
107
+ if File.exist?(fname)
108
+ puts "File exists."
109
+ else
110
+ puts "Writing to #{fname}"
111
+ `cp #{File.join(File.dirname(__FILE__), 'config', 'geonames.yml')} #{fname}`
112
+ end
113
+ exit
114
114
  end
115
- exit
116
- end
117
115
 
118
- #
119
- # Require georuby optionally
120
- #
121
- require "geo_ruby" if Opt[:mapping] && Opt[:mapping][:geom]
122
-
123
- #
124
- # Export Data as CSV or JSON
125
- #
126
- if argv[0] =~ /csv|json/
127
- Geonames::Export.new(Nation.all).to_csv
128
-
129
- #
130
- # Do the magic! Import Geonames Data
131
- #
132
- else
133
- load_adapter(Opt[:store])
134
- info "Using adapter #{Opt[:store]}.."
135
-
136
- # Nations
137
- if Opt[:nations].empty? || argv[0] =~ /coun|nati/
138
- info "\nPopulating 'nations' database..."
139
- dump = Geonames::Dump.new(:all, :dump)
140
- info "\n---\nTotal #{dump.data.length} parsed."
141
-
142
- info "Writing to nations DB"
143
- Geonames::Models::MongoWrapper.nations dump.data, Opt[:clean]
144
-
145
- # Regions, Cities....
116
+ #
117
+ # Require georuby optionally
118
+ #
119
+ require "geo_ruby" if Opt[:mapping] && Opt[:mapping][:geom]
120
+
121
+ #
122
+ # Load config if we got til here
123
+ #
124
+ load_config
125
+
126
+ #
127
+ # Export Data as CSV or JSON
128
+ #
129
+ if argv[0] =~ /csv|json/
130
+ Geonames::Export.new(Nation.all).to_csv
131
+
132
+ #
133
+ # Do the magic! Import Geonames Data
134
+ #
146
135
  else
147
- zip = Geonames::Dump.new(Opt[:nations], :zip).data
148
- dump = Geonames::Dump.new(Opt[:nations], :dump).data
149
- info "\n---\nTotal #{dump.size} parsed. #{zip.size} zips."
136
+ load_adapter(Opt[:store])
137
+ info "Using adapter #{Opt[:store]}.."
150
138
 
151
- info "Join dump << zip"
152
- dump = unify!(dump, zip).group_by(&:kind)
139
+ # Nations
140
+ if Opt[:nations].empty? || argv[0] =~ /coun|nati/
141
+ info "\nPopulating 'nations' database..."
142
+ dump = Geonames::Dump.new(:all, :dump)
143
+ info "\n---\nTotal #{dump.data.length} parsed."
153
144
 
154
- info "Writing to DB..."
155
- Geonames::Models::MongoWrapper.batch dump, Opt[:clean]
156
- # info "Writing cities..."
157
- # Geonames::Models::City.from_batch dump[:city]
145
+ info "Writing to nations DB"
146
+ Geonames::Models::MongoWrapper.nations dump.data, Opt[:clean]
147
+
148
+ # Regions, Cities....
149
+ else
150
+ zip = Geonames::Dump.new(Opt[:nations], :zip).data
151
+ dump = Geonames::Dump.new(Opt[:nations], :dump).data
152
+ info "\n---\nTotal #{dump.size} parsed. #{zip.size} zips."
153
+
154
+ info "Join dump << zip"
155
+ dump = unify!(dump, zip).group_by(&:kind)
156
+
157
+ info "Writing to DB..."
158
+ Geonames::Models::MongoWrapper.batch dump, Opt[:clean]
159
+ # info "Writing cities..."
160
+ # Geonames::Models::City.from_batch dump[:city]
161
+ end
158
162
  end
159
163
  end
160
- end
161
164
 
162
- def load_adapter(name)
163
- begin
164
- require "geonames_local/models/#{name}"
165
- # rescue LoadError
166
- # puts "Can't find adapter for #{name}"
167
- # stop!
165
+ def load_adapter(name)
166
+ begin
167
+ require "geonames_local/models/#{name}"
168
+ # rescue LoadError
169
+ # puts "Can't find adapter for #{name}"
170
+ # stop!
171
+ end
168
172
  end
169
- end
170
173
 
171
- def unify! dump, zip
172
- start = Time.now
173
- dump.map! do |spot|
174
- if other = zip.find { |d| d.code == spot.code }
175
- spot.zip = other.zip
176
- spot
177
- else
178
- spot
174
+ def unify! dump, zip
175
+ start = Time.now
176
+ dump.map! do |spot|
177
+ if other = zip.find { |d| d.code == spot.code }
178
+ spot.zip = other.zip
179
+ spot
180
+ else
181
+ spot
182
+ end
179
183
  end
184
+ info "Done. #{(Time.now-start).to_i}s"
185
+ dump
180
186
  end
181
- info "Done. #{(Time.now-start).to_i}s"
182
- dump
183
- end
184
187
 
185
- def stop!
186
- puts "Closing Geonames..."
187
- exit
188
- end
189
- end
188
+ def stop!
189
+ puts "Closing Geonames..."
190
+ exit
191
+ end
192
+
193
+
194
+ end # class < self
190
195
 
191
- end
196
+ end # CLI
192
197
 
193
- end
198
+ end # Geonames
@@ -10,7 +10,7 @@
10
10
  :geom: true
11
11
  :db:
12
12
  :host: localhost
13
- :dbname: geonames_local
13
+ :name: geonames_local
14
14
  # :user:
15
15
  # :password:
16
16
  # :purge: false
@@ -4,6 +4,7 @@ require 'geopolitical/helpers'
4
4
 
5
5
  Mongoid.configure do |config|
6
6
  #config.master = Mongo::Connection.new.db("symbolize_test")
7
+ info "Mongoid connecting to #{Opt[:db]}"
7
8
  config.connect_to(Opt[:db][:name])
8
9
  end
9
10
 
@@ -34,9 +35,10 @@ module Geonames
34
35
  end
35
36
 
36
37
  def create klass, data
38
+ info "#{klass}.new #{data}"
37
39
  klass.create! data
38
40
  rescue => e
39
- info "Prob com spot #{klass}, #{data} #{e}"
41
+ warn "Prob com spot #{e} #{e.backtrace.join("\n")}"
40
42
  end
41
43
 
42
44
  def translate txt
@@ -1,3 +1,3 @@
1
1
  module Geonames
2
- VERSION = '3.1.3'
2
+ VERSION = '3.3.0'
3
3
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geonames_local
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-07 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2013-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mongoid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: geopolitical
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.0
13
41
  description: Dumps geonames data to feed a local db
14
42
  email: x@nofxx.com
15
43
  executables:
@@ -17,13 +45,13 @@ executables:
17
45
  extensions: []
18
46
  extra_rdoc_files:
19
47
  - MIT-LICENSE
20
- - README.rdoc
48
+ - README.md
21
49
  files:
22
50
  - ".gitignore"
23
51
  - Gemfile
24
52
  - Guardfile
25
53
  - MIT-LICENSE
26
- - README.rdoc
54
+ - README.md
27
55
  - Rakefile
28
56
  - bin/geonames
29
57
  - geonames.yml
@@ -68,13 +96,10 @@ post_install_message: |2
68
96
  Geonames Local
69
97
  --------------
70
98
 
71
- To use the adapter, install the corresponding gem:
99
+ Use `geonames init` to create a config.yml file.
100
+ Or `geonames -c config.yml` to run using a config file.
72
101
 
73
- PostgreSQL => pg
74
- MongoDB => mongoid (optional: mongo_ext)
75
- Tokyo => tokyocabinet
76
-
77
- Have fun because:
102
+ Have fun!
78
103
  rdoc_options: []
79
104
  require_paths:
80
105
  - lib