peripatetic 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.
@@ -0,0 +1,268 @@
1
+ #!/bin/bash
2
+ #===============================================================================
3
+ #
4
+ # FILE: getgeo.sh
5
+ #
6
+ # USAGE: ./getgeo.sh
7
+ #
8
+ # DESCRIPTION: run the script so that the geodata will be downloaded and inserted into your
9
+ # database
10
+ #
11
+ # OPTIONS: ---
12
+ # REQUIREMENTS: ---
13
+ # BUGS: ---
14
+ # NOTES: ---
15
+ # AUTHOR: Andreas (aka Harpagophyt )
16
+ # COMPANY: <a href="http://forum.geonames.org/gforum/posts/list/926.page" target="_blank" rel="nofollow">http://forum.geonames.org/gforum/posts/list/926.page</a>
17
+ # VERSION: 1.4
18
+ # CREATED: 07/06/2008
19
+ # REVISION: 1.1 2008-06-07 replace COPY continentCodes through INSERT statements.
20
+ # 1.2 2008-11-25 Adjusted by Bastiaan Wakkie in order to not unnessisarily
21
+ # download.
22
+ # 1.3 2011-08-07 Updated script with tree changes. Removes 2 obsolete records from "countryinfo" dump image,
23
+ # updated timeZones table with raw_offset and updated postalcode to varchar(20).
24
+ # 1.4 2012-03-31 Don Drake - Add FKs after data is loaded, also vacuum analyze tables to ensure FK lookups use PK
25
+ # - Don't unzip text files
26
+ # - added DROP TABLE IF EXISTS
27
+ # 1.5 2012-06-30 Furdui Marian - added CountryCode to TimeZones and updated geonames.alternatenames to varchar(8000)
28
+ #===============================================================================
29
+
30
+ WORKPATH="${HOME}/geonames/geodata"
31
+ TMPPATH="tmp"
32
+ PCPATH="pc"
33
+ PREFIX="_"
34
+ DBHOST="localhost"
35
+ DBPORT="5432"
36
+ DBUSER="scott"
37
+ FILES="allCountries.zip alternateNames.zip userTags.zip admin1CodesASCII.txt admin2Codes.txt countryInfo.txt featureCodes_en.txt iso-languagecodes.txt timeZones.txt"
38
+ psql -U $DBUSER -h $DBHOST -p $DBPORT -c "CREATE DATABASE geonames WITH TEMPLATE = template0 ENCODING = 'UTF8';"
39
+ psql -U $DBUSER -h $DBHOST -p $DBPORT geonames <<EOT
40
+ DROP TABLE IF EXISTS geoname CASCADE;
41
+ CREATE TABLE geoname (
42
+ geonameid int,
43
+ name varchar(200),
44
+ asciiname varchar(200),
45
+ alternatenames varchar(8000),
46
+ latitude float,
47
+ longitude float,
48
+ fclass char(1),
49
+ fcode varchar(10),
50
+ country varchar(2),
51
+ cc2 varchar(60),
52
+ admin1 varchar(20),
53
+ admin2 varchar(80),
54
+ admin3 varchar(20),
55
+ admin4 varchar(20),
56
+ population bigint,
57
+ elevation int,
58
+ gtopo30 int,
59
+ timezone varchar(40),
60
+ moddate date
61
+ );
62
+
63
+ DROP TABLE IF EXISTS alternatename;
64
+ CREATE TABLE alternatename (
65
+ alternatenameId int,
66
+ geonameid int,
67
+ isoLanguage varchar(7),
68
+ alternateName varchar(300),
69
+ isPreferredName boolean,
70
+ isShortName boolean,
71
+ isColloquial boolean,
72
+ isHistoric boolean
73
+ );
74
+
75
+ DROP TABLE IF EXISTS countryinfo;
76
+ CREATE TABLE "countryinfo" (
77
+ iso_alpha2 char(2),
78
+ iso_alpha3 char(3),
79
+ iso_numeric integer,
80
+ fips_code character varying(3),
81
+ country character varying(200),
82
+ capital character varying(200),
83
+ areainsqkm double precision,
84
+ population integer,
85
+ continent char(2),
86
+ tld CHAR(10),
87
+ currency_code char(3),
88
+ currency_name CHAR(15),
89
+ phone character varying(20),
90
+ postal character varying(60),
91
+ postalRegex character varying(200),
92
+ languages character varying(200),
93
+ geonameId int,
94
+ neighbours character varying(50),
95
+ equivalent_fips_code character varying(3)
96
+ );
97
+
98
+
99
+
100
+ DROP TABLE IF EXISTS iso_languagecodes;
101
+ CREATE TABLE iso_languagecodes(
102
+ iso_639_3 CHAR(4),
103
+ iso_639_2 VARCHAR(50),
104
+ iso_639_1 VARCHAR(50),
105
+ language_name VARCHAR(200)
106
+ );
107
+
108
+
109
+ DROP TABLE IF EXISTS admin1CodesAscii;
110
+ CREATE TABLE admin1CodesAscii (
111
+ code CHAR(20),
112
+ name TEXT,
113
+ nameAscii TEXT,
114
+ geonameid int
115
+ );
116
+
117
+ DROP TABLE IF EXISTS admin2CodesAscii;
118
+ CREATE TABLE admin2CodesAscii (
119
+ code CHAR(80),
120
+ name TEXT,
121
+ nameAscii TEXT,
122
+ geonameid int
123
+ );
124
+
125
+ DROP TABLE IF EXISTS featureCodes;
126
+ CREATE TABLE featureCodes (
127
+ code CHAR(7),
128
+ name VARCHAR(200),
129
+ description TEXT
130
+ );
131
+
132
+ DROP TABLE IF EXISTS timeZones;
133
+ CREATE TABLE timeZones (
134
+ countrycode char(2),
135
+ timeZoneId VARCHAR(200),
136
+ GMT_offset numeric(3,1),
137
+ DST_offset numeric(3,1),
138
+ raw_offset numeric(3,1)
139
+ );
140
+
141
+ DROP TABLE IF EXISTS continentCodes;
142
+ CREATE TABLE continentCodes (
143
+ code CHAR(2),
144
+ name VARCHAR(20),
145
+ geonameid INT
146
+ );
147
+
148
+ DROP TABLE IF EXISTS postalcodes;
149
+ CREATE TABLE postalcodes (
150
+ countrycode char(2),
151
+ postalcode varchar(20),
152
+ placename varchar(180),
153
+ admin1name varchar(100),
154
+ admin1code varchar(20),
155
+ admin2name varchar(100),
156
+ admin2code varchar(20),
157
+ admin3name varchar(100),
158
+ admin3code varchar(20),
159
+ latitude float,
160
+ longitude float,
161
+ accuracy smallint
162
+ );
163
+
164
+ ALTER TABLE ONLY countryinfo
165
+ ADD CONSTRAINT pk_iso_alpha2 PRIMARY KEY (iso_alpha2);
166
+ EOT
167
+
168
+ # check if needed directories do already exsist
169
+ if [ -d "$WORKPATH" ]; then
170
+ echo "$WORKPATH exists..."
171
+ sleep 0
172
+ else
173
+ echo "$WORKPATH and subdirectories will be created..."
174
+ mkdir -p $WORKPATH
175
+ mkdir -p $WORKPATH/$TMPPATH
176
+ mkdir -p $WORKPATH/$PCPATH
177
+ echo "created $WORKPATH"
178
+ fi
179
+ echo
180
+ echo ",---- STARTING (downloading, unpacking and preparing)"
181
+ cd $WORKPATH/$TMPPATH
182
+ for i in $FILES
183
+ do
184
+ wget -N -q "http://download.geonames.org/export/dump/$i" # get newer files
185
+ if [ $i -nt $PREFIX$i ] || [ ! -e $PREFIX$i ] ; then
186
+ cp -p $i $PREFIX$i
187
+ if [ `expr index zip $i` -eq 1 ]; then
188
+ unzip -o -u -q $i
189
+ fi
190
+ case "$i" in
191
+ iso-languagecodes.txt)
192
+ tail -n +2 iso-languagecodes.txt > iso-languagecodes.txt.tmp;
193
+ ;;
194
+ countryInfo.txt)
195
+ grep -v '^#' countryInfo.txt | head -n -2 > countryInfo.txt.tmp;
196
+ ;;
197
+ timeZones.txt)
198
+ tail -n +2 timeZones.txt > timeZones.txt.tmp;
199
+ ;;
200
+ esac
201
+ echo "| $i has been downloaded";
202
+ else
203
+ echo "| $i is already the latest version"
204
+ fi
205
+ done
206
+ # download the postalcodes. You must know yourself the url
207
+ cd $WORKPATH/$PCPATH
208
+ wget -q -N "http://download.geonames.org/export/zip/allCountries.zip"
209
+ if [ $WORKPATH/$PCPATH/allCountries.zip -nt $WORKPATH/$PCPATH/allCountries$PREFIX.zip ] || [ ! -e $WORKPATH/$PCPATH/allCountries.zip ]; then
210
+ echo "Attempt to unzip $WORKPATH/$PCPATH/allCountries.zip file..."
211
+ unzip -o -u -q $WORKPATH/$PCPATH/allCountries.zip
212
+ cp -p $WORKPATH/$PCPATH/allCountries.zip $WORKPATH/$PCPATH/allCountries$PREFIX.zip
213
+ echo "| ....zip has been downloaded"
214
+ else
215
+ echo "| ....zip is already the latest version"
216
+ fi
217
+
218
+ echo "+---- FILL DATABASE ( this takes 2 days on my machine )"
219
+
220
+ psql -e -U $DBUSER -h $DBHOST -p $DBPORT geonames <<EOT
221
+ copy geoname (geonameid,name,asciiname,alternatenames,latitude,longitude,fclass,fcode,country,cc2,admin1,admin2,admin3,admin4,population,elevation,gtopo30,timezone,moddate) from '${WORKPATH}/${TMPPATH}/allCountries.txt' null as '';
222
+ ALTER TABLE ONLY geoname
223
+ ADD CONSTRAINT pk_geonameid PRIMARY KEY (geonameid);
224
+ vacuum analyze verbose geoname;
225
+
226
+ copy postalcodes (countrycode,postalcode,placename,admin1name,admin1code,admin2name,admin2code,admin3name,admin3code,latitude,longitude,accuracy) from '${WORKPATH}/${PCPATH}/allCountries.txt' null as '';
227
+ vacuum analyze verbose postalcodes;
228
+
229
+ copy timeZones (countrycode,timeZoneId,GMT_offset,DST_offset,raw_offset) from '${WORKPATH}/${TMPPATH}/timeZones.txt.tmp' null as '';
230
+ vacuum analyze verbose timeZones;
231
+
232
+ copy featureCodes (code,name,description) from '${WORKPATH}/${TMPPATH}/featureCodes_en.txt' null as '';
233
+ vacuum analyze verbose featureCodes;
234
+
235
+ copy admin1CodesAscii (code,name,nameAscii,geonameid) from '${WORKPATH}/${TMPPATH}/admin1CodesASCII.txt' null as '';
236
+ vacuum analyze verbose admin1CodesAscii;
237
+
238
+ copy admin2CodesAscii (code,name,nameAscii,geonameid) from '${WORKPATH}/${TMPPATH}/admin2Codes.txt' null as '';
239
+ vacuum analyze verbose admin2CodesAscii;
240
+
241
+ copy iso_languagecodes (iso_639_3,iso_639_2,iso_639_1,language_name) from '${WORKPATH}/${TMPPATH}/iso-languagecodes.txt.tmp' null as '';
242
+ vacuum analyze verbose iso_languagecodes;
243
+
244
+ copy countryInfo (iso_alpha2,iso_alpha3,iso_numeric,fips_code,country,capital,areainsqkm,population,continent,tld,currency_code,currency_name,phone,postal,postalRegex,languages,geonameid,neighbours,equivalent_fips_code) from '${WORKPATH}/${TMPPATH}/countryInfo.txt.tmp' null as '';
245
+ ALTER TABLE ONLY countryinfo
246
+ ADD CONSTRAINT fk_geonameid FOREIGN KEY (geonameid) REFERENCES geoname(geonameid);
247
+ vacuum analyze verbose countryInfo;
248
+
249
+ copy alternatename (alternatenameid,geonameid,isoLanguage,alternateName,isPreferredName,isShortName,isColloquial,isHistoric) from '${WORKPATH}/${TMPPATH}/alternateNames.txt' null as '';
250
+ ALTER TABLE ONLY alternatename
251
+ ADD CONSTRAINT pk_alternatenameid PRIMARY KEY (alternatenameid);
252
+ ALTER TABLE ONLY alternatename
253
+ ADD CONSTRAINT fk_geonameid FOREIGN KEY (geonameid) REFERENCES geoname(geonameid);
254
+ vacuum analyze verbose alternatename;
255
+
256
+ INSERT INTO continentCodes VALUES ('AF', 'Africa', 6255146);
257
+ INSERT INTO continentCodes VALUES ('AS', 'Asia', 6255147);
258
+ INSERT INTO continentCodes VALUES ('EU', 'Europe', 6255148);
259
+ INSERT INTO continentCodes VALUES ('NA', 'North America', 6255149);
260
+ INSERT INTO continentCodes VALUES ('OC', 'Oceania', 6255150);
261
+ INSERT INTO continentCodes VALUES ('SA', 'South America', 6255151);
262
+ INSERT INTO continentCodes VALUES ('AN', 'Antarctica', 6255152);
263
+ vacuum analyze verbose continentCodes;
264
+
265
+ CREATE INDEX index_countryinfo_geonameid ON countryinfo USING hash (geonameid);
266
+ CREATE INDEX index_alternatename_geonameid ON alternatename USING hash (geonameid);
267
+ EOT
268
+ echo "'----- DONE ( have fun... )"
@@ -0,0 +1,6 @@
1
+ countries.yml is from countries gem https://github.com/hexorx/countries
2
+
3
+ import_geonames downloads and imports geonames db. http://download.geonames.org/export/dump/
4
+
5
+ free-zipcode-database-Primary.csv is from http://federalgovernmentzipcodes.us/
6
+
@@ -0,0 +1,11 @@
1
+ require 'peripatetic'
2
+
3
+ describe Peripatetic::Locationable do
4
+ it "broccoli is gross" do
5
+ Peripatetic::Locationable.portray("Broccoli").should eql("Gross!")
6
+ end
7
+
8
+ it "anything else is delicious" do
9
+ Peripatetic::Locationable.portray("Not Broccoli").should eql("Delicious!")
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peripatetic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-17 00:00:00.000000000 Z
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: geocoder
@@ -59,22 +59,40 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- description: Something neat yo
62
+ description: Drop in location functionality for any app
63
63
  email:
64
64
  - scottsmit@gmail.com
65
65
  executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
+ - .DS_Store
69
70
  - .gitignore
70
71
  - Gemfile
71
72
  - LICENSE.txt
72
73
  - README.md
73
74
  - Rakefile
75
+ - lib/generators/db/create_countries.rb
76
+ - lib/generators/db/create_locations_table.rb
77
+ - lib/generators/db/create_postal_codes_table.rb
78
+ - lib/generators/rake/dump_and_load.rake
74
79
  - lib/peripatetic.rb
80
+ - lib/peripatetic/.DS_Store
81
+ - lib/peripatetic/country.rb
82
+ - lib/peripatetic/location.rb
83
+ - lib/peripatetic/peripateticize.rb
84
+ - lib/peripatetic/postal_code.rb
85
+ - lib/peripatetic/railtie.rb
75
86
  - lib/peripatetic/version.rb
76
87
  - peripatetic.gemspec
77
- homepage: http://scoran.com
88
+ - preparing/add_rename_remove.rb
89
+ - preparing/clean_db.rb
90
+ - preparing/countries.yaml
91
+ - preparing/free-zipcode-database-Primary.csv
92
+ - preparing/import_geonames.sh
93
+ - preparing/readme.txt
94
+ - test/spec/peripatetic_spec.rb
95
+ homepage: https://github.com/davingee/Peripatetic
78
96
  licenses: []
79
97
  post_install_message:
80
98
  rdoc_options: []
@@ -97,5 +115,9 @@ rubyforge_project:
97
115
  rubygems_version: 1.8.24
98
116
  signing_key:
99
117
  specification_version: 3
100
- summary: Something neat yo
101
- test_files: []
118
+ summary: This gem adds location functionality to any app it create 3 tables in the
119
+ database (locations, countries, and postal_codes) and populates countries and postal_codes
120
+ from a compressed yaml file. One may specify wether it be has_one or has_many. The
121
+ countries and postal_codes table are just look up tables
122
+ test_files:
123
+ - test/spec/peripatetic_spec.rb