ntsb 0.9.0
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 +7 -0
- data/CHANGELOG.md +14 -0
- data/MIT-LICENSE +20 -0
- data/README.md +42 -0
- data/exe/ntsb +4 -0
- data/lib/ntsb/cli.rb +64 -0
- data/lib/ntsb/version.rb +4 -0
- data/lib/ntsb.rb +9 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fa271e31e982d9ea5a2aebb9ffd45480a6c877d7f4e0dcaea61986eb24445e8e
|
|
4
|
+
data.tar.gz: 2b8bb52694e1da70c14a720b2c0d5d266710b68b6a7e5f8c64dc4dafda412af0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 77a4e8a249d380cc56a1be4debb09164a5750d5cea1852968a9f5f60c77c1276ae10113e34b67f0ed9076c3e2e50c2a9c81906015a9466364b4e7ef718993187
|
|
7
|
+
data.tar.gz: e3bcf20e831d3acfa9011b093faad034582fad2e60d7c4948b126d23030198f0f968e4c14663e233b2133e30b67fd9848774d405caec7358ea41df63d99c6aa0
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
For more information about changelogs, check [Keep a Changelog](http://keepachangelog.com).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## 0.9.0 - 2026-10-05
|
|
10
|
+
|
|
11
|
+
* [FEATURE] The `ntsb` command
|
|
12
|
+
|
|
13
|
+
`ntsb -n 2632l` prints every event the NTSB recorded for an N-number, and `--json` the same
|
|
14
|
+
as JSON.
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2026 Claudio Baccigalupo
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# ntsb
|
|
2
|
+
|
|
3
|
+
The `ntsb` command: every accident and incident the NTSB recorded for an aircraft, read in a
|
|
4
|
+
terminal.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
ntsb -n 2632l # every event naming N2632L, each table of it, codes explained
|
|
8
|
+
ntsb -n 2632l --json # the same, as JSON
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The answers come from a copy of the NTSB's database refreshed every night, at
|
|
12
|
+
https://accidents.easyfaa.com. `NTSB_URL` names another one. Each address may ask 20 times a
|
|
13
|
+
minute and 200 times a day.
|
|
14
|
+
|
|
15
|
+
An NTSB record names the N-number the aircraft had then: an N-number the FAA has since given
|
|
16
|
+
another aircraft lists that aircraft's events too.
|
|
17
|
+
|
|
18
|
+
## How to install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
gem install ntsb
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
# Gemfile
|
|
26
|
+
gem 'ntsb', '~> 0.9'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`~> 0.9` takes every 0.x from 0.9 on and never 1.0: until 1.0, a minor version may change what the command prints.
|
|
30
|
+
|
|
31
|
+
For the FAA's registry and Airworthiness Directives, see the `faa` command (`gem install easyfaa`).
|
|
32
|
+
|
|
33
|
+
## Development
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bin/setup # the bundle
|
|
37
|
+
bundle exec rake # the suite at 100% line coverage, and RuboCop
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
[MIT](MIT-LICENSE).
|
data/exe/ntsb
ADDED
data/lib/ntsb/cli.rb
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
|
|
3
|
+
module NTSB
|
|
4
|
+
# The `ntsb` command: what the NTSB publishes about the events of an N-number
|
|
5
|
+
# (`ntsb -n 2632l`), as text, or as JSON with `--json`.
|
|
6
|
+
class CLI
|
|
7
|
+
# Each option, and the page it asks for.
|
|
8
|
+
PAGES = { '-n' => 'N' }.freeze
|
|
9
|
+
|
|
10
|
+
# What `ntsb --help` prints.
|
|
11
|
+
USAGE = <<~TEXT.freeze
|
|
12
|
+
Usage: ntsb -n N-NUMBER [--json] every accident and incident the NTSB recorded for it
|
|
13
|
+
ntsb --version
|
|
14
|
+
|
|
15
|
+
Reads NTSB_URL, where the data is served (#{URL} unless set).
|
|
16
|
+
TEXT
|
|
17
|
+
|
|
18
|
+
# @param args [Array<String>] command-line arguments.
|
|
19
|
+
# @param out [IO] where the answer is printed.
|
|
20
|
+
# @param err [IO] where a problem is printed.
|
|
21
|
+
def initialize(args, out: $stdout, err: $stderr)
|
|
22
|
+
@args = args
|
|
23
|
+
@out = out
|
|
24
|
+
@err = err
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Prints what was asked for.
|
|
28
|
+
# @return [Integer] exit status: 0 when it was found, 1 otherwise.
|
|
29
|
+
def run
|
|
30
|
+
option, number, format = @args
|
|
31
|
+
if %w[-v --version].include?(option) then answer "ntsb #{VERSION}"
|
|
32
|
+
elsif PAGES.key?(option) && number then fetch PAGES[option], number, format
|
|
33
|
+
else answer USAGE, status: option.nil? || %w[-h --help].include?(option) ? 0 : 1
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def fetch(page, number, format)
|
|
40
|
+
extension = format == '--json' ? 'json' : 'txt'
|
|
41
|
+
response = Net::HTTP.get_response URI("#{url}/#{page}/#{escape number}.#{extension}")
|
|
42
|
+
case response
|
|
43
|
+
when Net::HTTPSuccess then answer response.body
|
|
44
|
+
when Net::HTTPNotFound then problem "The NTSB records nothing under #{number}."
|
|
45
|
+
when Net::HTTPTooManyRequests then problem 'Too many requests: try again in a minute.'
|
|
46
|
+
else problem "#{url} answered #{response.code}."
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def escape(number) = URI.encode_www_form_component(number)
|
|
51
|
+
|
|
52
|
+
def url = ENV.fetch('NTSB_URL', URL).chomp('/')
|
|
53
|
+
|
|
54
|
+
def answer(text, status: 0)
|
|
55
|
+
@out.puts text
|
|
56
|
+
status
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def problem(text)
|
|
60
|
+
@err.puts text
|
|
61
|
+
1
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/ntsb/version.rb
ADDED
data/lib/ntsb.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'ntsb/version'
|
|
2
|
+
|
|
3
|
+
# What the NTSB publishes about the accidents and incidents of an aircraft, read in a terminal.
|
|
4
|
+
module NTSB
|
|
5
|
+
# Where the NTSB's data is served, unless NTSB_URL says otherwise.
|
|
6
|
+
URL = 'https://accidents.easyfaa.com'.freeze
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
require 'ntsb/cli'
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ntsb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.9.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- claudiob
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: "`ntsb -n 2632l` prints every event the NTSB recorded for an N-number,
|
|
13
|
+
every table of each, as the NTSB published it."
|
|
14
|
+
email:
|
|
15
|
+
- claudiob@users.noreply.github.com
|
|
16
|
+
executables:
|
|
17
|
+
- ntsb
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- CHANGELOG.md
|
|
22
|
+
- MIT-LICENSE
|
|
23
|
+
- README.md
|
|
24
|
+
- exe/ntsb
|
|
25
|
+
- lib/ntsb.rb
|
|
26
|
+
- lib/ntsb/cli.rb
|
|
27
|
+
- lib/ntsb/version.rb
|
|
28
|
+
homepage: https://github.com/easyfaa/ntsb
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata:
|
|
32
|
+
source_code_uri: https://github.com/easyfaa/ntsb
|
|
33
|
+
changelog_uri: https://github.com/easyfaa/ntsb/blob/main/CHANGELOG.md
|
|
34
|
+
documentation_uri: https://rubydoc.info/gems/ntsb
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '3.1'
|
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
requirements: []
|
|
49
|
+
rubygems_version: 4.0.3
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: 'The ntsb command: every accident and incident the NTSB recorded for an aircraft.'
|
|
52
|
+
test_files: []
|