forked from mahemoff/geodata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.rb
More file actions
executable file
·26 lines (26 loc) · 730 Bytes
/
Copy pathparse.rb
File metadata and controls
executable file
·26 lines (26 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env ruby
require 'json'
cities = {}
city = nil
key = nil
File.foreach('cities.txt') { |s|
if s =~ /^lat:/
# cities.push city if city
cities[key] = city if city
city = {}
end
if s =~ /^(lat|lon): "(.*)"/
field = $1
$2 =~ /(-)?(\d+).*?(\d+)/
deg = $2.to_f + $3.to_f/60
deg = -deg if $1=='-'
city[field] = format("%.3f", deg).to_f
elsif s =~ /^city_wiki: "(.*)"/
city['wikipedia'] = $1
city['city'] = $1.gsub(/,.+/,'').gsub('_',' ')
# remove whitespace and modifier suffixes like (city)
key = city['city'].downcase.gsub(/[ -]/,'').gsub(/\(.*?\)/,'')
end
}
# puts "citiesCallback(#{cities.to_json});"
puts "citiesCallback(#{JSON.pretty_generate(cities)});"