city_utc 1.0.3 → 1.0.5
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.
- checksums.yaml +4 -4
- data/sources/city_utc/models/city.rb +6 -6
- data/sources/city_utc/models/timezone.rb +1 -1
- data/sources/city_utc/sqlite.rb +4 -5
- data/sources/city_utc/utc_time.rb +2 -2
- data/sources/database/sqlite.db.gz +0 -0
- data/spec/integration/city_utc_db_spec.rb +2 -2
- data/spec/integration/city_utc_web_spec.rb +4 -4
- data/spec/tserver/utc_time_spec.rb +4 -4
- data/tasks/database.rake +14 -12
- data/tasks/server.rake +2 -2
- data/tasks/timezones_converter.rake +37 -35
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2343450636306b04bfae4726b8798130c95eaac
|
4
|
+
data.tar.gz: 8172d54d3305360d3a9d0d6ac50af16318853363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 342d51d9e8e424cfee494bb53436d03ddcefe682d0a1fe92c9039dc8e66b921d861f31738404f531395370ab8f31b189be85ddd219fbd8f4bd4d3b2829e883c7
|
7
|
+
data.tar.gz: 69ef914f7e8f1d7f26b451b0704a120dd1803302680824382c987a6d3e9cce0d66bbf51887bd273fbf7f159caef7fe6b953bc484c3f78b2fff4098243ef5d457
|
@@ -4,12 +4,12 @@ module CityUTC
|
|
4
4
|
# == Schema for `cities` table
|
5
5
|
#
|
6
6
|
# CREATE TABLE `cities` (
|
7
|
-
# `id`
|
8
|
-
# `city`
|
9
|
-
# `country`
|
10
|
-
# `latitude`
|
11
|
-
# `longitude`
|
12
|
-
# `population`
|
7
|
+
# `id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
8
|
+
# `city` TEXT,
|
9
|
+
# `country` TEXT,
|
10
|
+
# `latitude` REAL,
|
11
|
+
# `longitude` REAL,
|
12
|
+
# `population` INTEGER,
|
13
13
|
# `timezone_code` INTEGER
|
14
14
|
# );
|
15
15
|
class City < Sequel::Model
|
data/sources/city_utc/sqlite.rb
CHANGED
@@ -12,16 +12,15 @@ module CityUTC
|
|
12
12
|
private_class_method :restore_database
|
13
13
|
|
14
14
|
def self.restorable? # no-doc
|
15
|
-
|
16
|
-
|
15
|
+
path_to_archive = File.join(__dir__, '..', 'database', 'sqlite.db.gz')
|
16
|
+
path_to_database = File.join(__dir__, '..', 'database', 'sqlite.db')
|
17
17
|
|
18
|
-
File.exist?(
|
18
|
+
File.exist?(path_to_archive) && !File.exist?(path_to_database)
|
19
19
|
end
|
20
20
|
private_class_method :restorable?
|
21
21
|
|
22
22
|
def self.connect_to_db # no-doc
|
23
|
-
path_to_database =
|
24
|
-
File.join(__dir__, '..', 'database', 'sqlite.db')
|
23
|
+
path_to_database = File.join(__dir__, '..', 'database', 'sqlite.db')
|
25
24
|
|
26
25
|
Sequel.connect "sqlite://#{path_to_database}"
|
27
26
|
end
|
@@ -28,8 +28,8 @@ module CityUTC
|
|
28
28
|
# Presents time instance as pretty formatted string.
|
29
29
|
#
|
30
30
|
# @example
|
31
|
-
# time
|
32
|
-
#
|
31
|
+
# time # ==> 2017-01-13 12:37:34 UTC
|
32
|
+
# pretty_formatted(time) # ==> "UTC: 2017-01-13 12:37:34"
|
33
33
|
#
|
34
34
|
# @param [Time] time
|
35
35
|
#
|
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe "As database
|
4
|
+
describe "As database" do
|
5
5
|
it 'it creates valid Sequel::Model relation for Cities table' do
|
6
6
|
cities = CityUTC::City
|
7
7
|
|
@@ -12,4 +12,4 @@ describe "As database." do
|
|
12
12
|
.to_a.collect(&:city)
|
13
13
|
).to contain_exactly "tokyo", "shanghai", "bombay"
|
14
14
|
end
|
15
|
-
end # describe "As database
|
15
|
+
end # describe "As database"
|
@@ -4,7 +4,7 @@ require 'net/http'
|
|
4
4
|
|
5
5
|
# To pass this tests launch the server!
|
6
6
|
# TODO add rspec helper to check server state and launch up when s isn't started
|
7
|
-
describe "As
|
7
|
+
describe "As web application" do
|
8
8
|
context 'When client sends valid request' do
|
9
9
|
it 'returns time' do
|
10
10
|
uri = URI('http://127.0.0.1/time?')
|
@@ -43,7 +43,7 @@ describe "As Web Server." do
|
|
43
43
|
|
44
44
|
expect(response.body).to match /UNKNOWN/
|
45
45
|
end
|
46
|
-
end # context 'valid request'
|
46
|
+
end # context 'When client sends valid request'
|
47
47
|
|
48
48
|
# ----------------------------------------------------
|
49
49
|
|
@@ -59,5 +59,5 @@ describe "As Web Server." do
|
|
59
59
|
expect(response.body)
|
60
60
|
.to match /Please use get http request for 'time' api endpoint/
|
61
61
|
end
|
62
|
-
end # context 'invalid request'
|
63
|
-
end # describe "As
|
62
|
+
end # context 'When client sends invalid request'
|
63
|
+
end # describe "As web application"
|
@@ -8,7 +8,7 @@ module CityUTC
|
|
8
8
|
allow(Time).to receive(:now).and_return local_time
|
9
9
|
end
|
10
10
|
|
11
|
-
context '#
|
11
|
+
context '#for_city' do
|
12
12
|
it "returns +'UNKNOWN'+ when +:local_location+ unrecognized" do
|
13
13
|
expect(described_class.for_city('there_is_no_city_with_dat_name'))
|
14
14
|
.to be_eql "UNKNOWN"
|
@@ -29,11 +29,11 @@ module CityUTC
|
|
29
29
|
expect(described_class.for_city('Ufa').to_s)
|
30
30
|
.to be_eql("Ufa: 2015-04-11 15:30:50")
|
31
31
|
end
|
32
|
-
end # context '#
|
32
|
+
end # context '#for_city'
|
33
33
|
|
34
34
|
# ----------------------------------------------------
|
35
35
|
|
36
|
-
context '#
|
36
|
+
context '#pretty_formatted' do
|
37
37
|
it 'presents time as expected(formatted string)' do
|
38
38
|
expect(described_class.pretty_formatted(Time.now.utc))
|
39
39
|
.to be_eql("UTC: 2015-04-11 10:30:50")
|
@@ -43,6 +43,6 @@ module CityUTC
|
|
43
43
|
expect(described_class.pretty_formatted(Time.now.utc, "PREFIX"))
|
44
44
|
.to be_eql("PREFIX: 2015-04-11 10:30:50")
|
45
45
|
end
|
46
|
-
end # context '#
|
46
|
+
end # context '#pretty_formatted'
|
47
47
|
end # describe CityUTC
|
48
48
|
end # module CityUTC
|
data/tasks/database.rake
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
namespace :development do
|
4
|
+
desc 'Restores database'
|
5
|
+
task :restore_database! do
|
6
|
+
path_to_folder = File.join(__dir__, "..", "sources", "database")
|
7
|
+
path_to_database = File.join(path_to_folder, 'sqlite.db.gz')
|
7
8
|
|
8
|
-
|
9
|
-
end
|
9
|
+
Kernel.system "gzip -d #{path_to_database} #{path_to_folder}"
|
10
|
+
end
|
10
11
|
|
11
|
-
desc 'Compresses database'
|
12
|
-
task :compress_database! do
|
13
|
-
|
14
|
-
|
12
|
+
desc 'Compresses database'
|
13
|
+
task :compress_database! do
|
14
|
+
path_to_folder = File.join(__dir__, "..", "sources", "database")
|
15
|
+
path_to_database = File.join(path_to_folder, 'sqlite.db')
|
15
16
|
|
16
|
-
|
17
|
-
end
|
17
|
+
Kernel.system "gzip -k #{path_to_database} #{path_to_folder}"
|
18
|
+
end
|
19
|
+
end # namespace :development
|
data/tasks/server.rake
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
|
-
desc 'Launches web-server
|
4
|
-
task :
|
3
|
+
desc 'Launches web-server for CityUTC'
|
4
|
+
task :launch_city_utc_web_app! do
|
5
5
|
settings = [
|
6
6
|
'--max-conns 2048',
|
7
7
|
'--address 127.0.0.1',
|
@@ -1,45 +1,47 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
namespace :development do
|
4
|
+
desc "Note: requests ruby >= 2.4.0" \
|
5
|
+
"Creates two csv files for later import into sqlite db. " \
|
6
|
+
"Original file can been downloaded by following link: " \
|
7
|
+
"http://download.maxmind.com/download/worldcities/worldcitiespop.txt.gz"
|
8
|
+
# Note for csv to sqlite.db converting 'DB Browser for SQLite' was used.
|
9
|
+
task :prepare_for_import_to_db do
|
10
|
+
require 'csv'
|
11
|
+
require 'nearest_time_zone' # TODO remove dependency with original csv database
|
12
|
+
require 'timezone'
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
origin_csv = File.join(__dir__, '..', 'tmp', 'worldcitiespop.txt')
|
15
|
+
timezone_mapping = Hash.new
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
zones = Timezone.names.sort_by &:to_s
|
18
|
+
zones.each_with_index { |zone, index| timezone_mapping[zone] = index }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
list = []
|
21
|
+
CSV.foreach(origin_csv, encoding: 'iso-8859-1:utf-8', headers: true,
|
22
|
+
liberal_parsing: true) do |row|
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
city_name = row.fetch("City")
|
25
|
+
country = row.fetch("Country")
|
26
|
+
lat = row.fetch("Latitude").to_f.round(3)
|
27
|
+
lng = row.fetch("Longitude").to_f.round(3)
|
28
|
+
population = row.fetch("Population").to_i
|
29
|
+
timezone = NearestTimeZone.to(lat, lng)
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
list << [ city_name, country, lat, lng,
|
32
|
+
population, timezone_mapping[timezone] ]
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
path_to_mapping = File.join(__dir__, '..', 'tmp', 'timezones.csv')
|
36
|
+
CSV.open(path_to_mapping , "wb") do |csv|
|
37
|
+
csv << ["timezone", "code"]
|
38
|
+
timezone_mapping.each_pair { |key, value| csv << [key, value] }
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
path_to_new_csv = File.join(__dir__, '..', 'tmp', 'cities.csv')
|
42
|
+
CSV.open(path_to_new_csv, "wb") do |csv|
|
43
|
+
csv << ["city", "country", "latitude", "longitude", "population", "timezone_code"]
|
44
|
+
list.each { |row| csv << row }
|
45
|
+
end
|
44
46
|
end
|
45
|
-
end
|
47
|
+
end # namespace :development
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: city_utc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuzichev Michael
|
@@ -133,7 +133,7 @@ homepage: https://github.com/Medvedu/City-UTC
|
|
133
133
|
licenses:
|
134
134
|
- MIT
|
135
135
|
metadata: {}
|
136
|
-
post_install_message:
|
136
|
+
post_install_message:
|
137
137
|
rdoc_options: []
|
138
138
|
require_paths:
|
139
139
|
- sources
|
@@ -152,9 +152,11 @@ rubyforge_project:
|
|
152
152
|
rubygems_version: 2.6.8
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
|
-
summary: This project consist of two parts
|
156
|
-
two tables
|
157
|
-
|
155
|
+
summary: 'This project consist of two parts First part includes sqlite database with
|
156
|
+
two tables based on worldcitiespop.csv (http://download.maxmind.com/download/):
|
157
|
+
cities(city, country, latitude, longitude, population, timezone_code) timezones(timezone,
|
158
|
+
code) Second part is sinatra (web) application for work with the database throw
|
159
|
+
Sequel ORM.'
|
158
160
|
test_files:
|
159
161
|
- spec/tserver/utc_time_spec.rb
|
160
162
|
- spec/spec_helper.rb
|