Skip to content

Commit

Permalink
Merge pull request #32 from MatjazKavcic/update-data
Browse files Browse the repository at this point in the history
Update data patching, airports data
  • Loading branch information
Tim Rogers authored Jan 25, 2020
2 parents 500afa7 + 79537d1 commit ead690f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
27 changes: 3 additions & 24 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ end

task :update do
raw_data = open("https://raw.githubusercontent.com/jpatokal/openflights/master/data/" \
"airports.dat").read
"airports.dat").read + File.read("./data/patches.dat")

cleaned_data = raw_data.gsub(/\\"/, '""')

cleaned_data = CSV.parse(cleaned_data).each_with_object({}) do |row, accumulator|
# Doha is missing its IATA code, for some reason 🙄
iata_code = row[5] == "OTBD" ? "DOH" : row[4]
iata_code = row[4]

# We'll skip other airports which don't have IATA codes
next unless iata_code != "\\N"
Expand All @@ -45,27 +45,6 @@ task :update do
}
end

# Istanbul (IST) is missing its time zone, so add it in
cleaned_data["IST"][:tz_name] = "Europe/Istanbul"

# `CPC` has an abbreviation in its name ("C. Campos"), so expand it
cleaned_data["CPC"][:name] = "Aviador Carlos Campos Airport"

# Hyderabad (HYD) is missing, so add it in
cleaned_data["HYD"] = {
name: "Rajiv Gandhi International Airport",
city: "Hyderabad",
country: "India",
iata: "HYD",
icao: "VOHS",
latitude: "17.2403",
longitude: "78.4294",
altitude: nil,
timezone: "N",
dst: "5.5",
tz_name: "Asia/Calcutta",
}

File.open("data/airports.json", "w").puts JSON.generate(cleaned_data)
end

Expand Down
2 changes: 1 addition & 1 deletion data/airports.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions data/patches.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2517,"Aviador Carlos Campos Airport","San Martin Des Andes","Argentina","CPC","SAZY",-40.075401,-71.137299,2569,-3,"N","America/Argentina/Salta","airport","OurAirports"
11051,"Hamad International Airport","Doha","Qatar","DOH","OTHH",25.273056,51.608056,13,3,"N","Asia/Qatar","airport","OurAirports"
12087,"Rajiv Gandhi International Airport","Hyderabad","India","HYD","VOHS",17.2313175201,78.4298553467,2024,5.5,"N","Asia/Calcutta","airport","OurAirports"
13696,"Istanbul Airport","Istanbul","Turkey","IST","LTFM",41.275278,28.751944,325,3,"E","Europe/Istanbul","airport","OurAirports"
12 changes: 12 additions & 0 deletions spec/airports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
expect(Airports::VERSION).to_not be nil
end

describe "patches" do
subject(:find_by_iata_code) do
described_class.find_by_iata_code(iata_code)
end

context "applies to existing values" do
let(:iata_code) { "IST" }

its(:tz_name) { is_expected.to eq("Europe/Istanbul") }
end
end

describe ".find_by_iata_code" do
subject(:find_by_iata_code) do
described_class.find_by_iata_code(iata_code)
Expand Down

0 comments on commit ead690f

Please sign in to comment.