br_db 0.1.10 → 0.1.11
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/app/jobs/br_db/load_zip_codes_job.rb +26 -28
- data/lib/br_db/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2797923ff79f789a373c8e61927de2ce2250affca3c6e31ec3ca9255aa94b156
|
4
|
+
data.tar.gz: 89d651b3e1c87a3be3a3d8305228bc9459d1174264e4a5e0bc01d67ad60c8896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d30e38217c0d47d2d11feb94d644fbbaae7463efd0da21d854650bffc348e809e8abdcd7b53a5e381fce0f79e0109c19804dd60f5c7ad8ecd028097629540ab0
|
7
|
+
data.tar.gz: 371a0bd1c16356b7c003b147b75ce1683feac24cf3e15b99dbf8a8810ffb026eea8f992a2f45a56621bb7b267b4c077ce526f737715dcb61e86b0ad371ccf090
|
@@ -68,36 +68,34 @@ module BrDb
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def import_zip_codes
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
zip_codes = []
|
97
|
-
end
|
71
|
+
# The file name is log_logradouro_SC.txt or log_logradouro_SP.txt
|
72
|
+
csv_file_path_regex = /log_logradouro_(\w\w).txt/
|
73
|
+
path = DELIMITADO_FILE_PATH
|
74
|
+
city_mapping = get_data_map("log_localidade.txt", 2, 8)
|
75
|
+
neighborhood_mapping = get_data_map("log_bairro.txt", 3, 3)
|
76
|
+
|
77
|
+
zip_codes = []
|
78
|
+
# iterate over the csv files that match the regex pattern
|
79
|
+
Dir.glob(path.join("**", "*.txt")).each do |file_path|
|
80
|
+
next unless csv_file_path_regex.match?(file_path)
|
81
|
+
CSV.foreach(file_path, liberal_parsing: true, col_sep: DELIMITER, headers: false, encoding: ENCODING, quote_char: QUOTE_CHARS.shift) do |row|
|
82
|
+
street_name = row[8] + " " + row[5]
|
83
|
+
zip_codes << {
|
84
|
+
state_code: row[1],
|
85
|
+
neighborhood_name: neighborhood_mapping[row[3]][0],
|
86
|
+
street_name: street_name,
|
87
|
+
city_name: city_mapping[row[2]][0],
|
88
|
+
city_code: city_mapping[row[2]][1],
|
89
|
+
street_additional_info: row[6],
|
90
|
+
zip_code: row[7]
|
91
|
+
}
|
92
|
+
end
|
93
|
+
if zip_codes.count % 1_000 == 0
|
94
|
+
ZipCode.insert_all(zip_codes)
|
95
|
+
zip_codes = []
|
98
96
|
end
|
99
|
-
ZipCode.insert_all(zip_codes)
|
100
97
|
end
|
98
|
+
ZipCode.insert_all(zip_codes)
|
101
99
|
end
|
102
100
|
|
103
101
|
def import_city_zip_codes
|
data/lib/br_db/version.rb
CHANGED