airports 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38fb2f0178a12f7f82c84811cac9827259b3abd0
4
- data.tar.gz: 3cadaeb072f83a7fb32a0d70a62e071827e0d863
3
+ metadata.gz: 8815f8b4415b254f726bb075910b58c5110cc4fd
4
+ data.tar.gz: 55c2474dc7966cff0f68a7d82fbf68639c9a0267
5
5
  SHA512:
6
- metadata.gz: abae6605950eddd407f51de0ca95f504051631c64d6593318e56f0a0f8ff2fefb4b7c07dbcc18948421fdb6e1be9ce4c5d847a70f4bac61232493e4a7d0667be
7
- data.tar.gz: fbd0aaf593d5a6e32d1d8e3da779b5795e61136a3cea3b0a197c4c152710e8b8dad067a9a3b72c29097f994a30ac51f119fe7d02789c7f72beca27ed8dac1f95
6
+ metadata.gz: 64e0197e308c2f232ad49b566a13d19007bcf9224969e90135dc160431b36fffb0ee8be589727ae2fec670be4028d74c77aaf6dbbfeb49725d09856e1cfbce3f
7
+ data.tar.gz: 4f6d93a9bf1d3740ec5dc6ae32f02cf103b07f060c4c593cfb25c443c024c6f00707091f002aaa0342d7e0fc2b3e1c035a25a2a6bd36facfae52075493beb270
data/README.md CHANGED
@@ -4,12 +4,14 @@
4
4
 
5
5
  Airports gives you access to data on airports around the world.
6
6
 
7
+ It's based on data from [OpenFlights](http://openflights.org), with a bit of massaging on the way (dropping airports without an IATA code, giving Doha its IATA code and adding Hyderabad which is missing entirely).
8
+
7
9
  ## Usage
8
10
 
9
- Install the gem *(Ruby 2.1.0 and later only)*:
11
+ Install the gem by adding it to your Gemfile:
10
12
 
11
- ```bash
12
- $ gem install airports
13
+ ```ruby
14
+ gem 'airports', '~> 1.0.0'
13
15
  ```
14
16
 
15
17
  You can then look up an airport by its IATA code (e.g. `LHR` for London Heathrow) using `Airports.find_by_iata_code`, which returns an object with a bunch of accessors like `name` and `city`:
@@ -37,11 +39,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
37
39
 
38
40
  ## Contributing
39
41
 
40
- Bug reports and pull requests are welcome on GitHub at https://github.com/timrogers/mummy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
42
+ To update the data included in the gem, just run `bundle exec rake update` and make a pull request with the changes. This will pull the latest data from [OpenFlights](http://openflights.org).
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/timrogers/airports. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
41
45
 
42
46
  ## Acknowledgements
43
47
 
44
- The data is taken from <https://github.com/ram-nadella/airport-codes>, which uses source data from [OpenFlights](http://openflights.org/). Source data is included using [Git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules).
48
+ Big thanks to [OpenFlights](http://openflights.org) for collecting and making this data available. Check out their website for additional data about airlines, routes etc.
45
49
 
46
50
  ## License
47
51
 
data/Rakefile CHANGED
@@ -1,6 +1,51 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "csv"
4
+ require "json"
5
+ require "open-uri"
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec)
5
8
 
9
+ task :update do
10
+ raw_data = open("https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat").read
11
+ cleaned_data = raw_data.gsub(/\\"/,'""')
12
+
13
+ data = CSV.parse(cleaned_data).each_with_object({}) do |row, accumulator|
14
+ # Doha is missing its IATA code, for some reason 🙄
15
+ iata_code = row[5] == "OTBD" ? "DOH" : row[4]
16
+
17
+ accumulator[iata_code] = {
18
+ name: row[1],
19
+ city: row[2],
20
+ country: row[3],
21
+ iata: iata_code,
22
+ icao: row[5],
23
+ latitude: row[6],
24
+ longitude: row[7],
25
+ altitude: row[8],
26
+ timezone: row[9],
27
+ dst: row[10]
28
+ }
29
+ end.
30
+ tap do |data|
31
+ # Hyderabad (HYD) is missing, so add it in
32
+ data["HYD"] = {
33
+ name: "Rajiv Gandhi International Airport",
34
+ city: "Hyderabad",
35
+ country: "India",
36
+ iata: "HYD",
37
+ icao: "VOHS",
38
+ latitude: "17.2403",
39
+ longitude: "78.4294",
40
+ altitude: nil,
41
+ timezone: "N",
42
+ dst: "5.5",
43
+ }
44
+ end.
45
+ # We aren't interested in airports with no IATA code
46
+ reject { |code, _| code.nil? || code == "" }
47
+
48
+ File.open("data/airports.json", "w").puts JSON.generate(data)
49
+ end
50
+
6
51
  task :default => :spec