flightcheck 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flightcheck.rb +56 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e305044fb746cf2c50727f31bd1075b81022186
|
4
|
+
data.tar.gz: b1a3d8eeeea3f267364310c44223a7f7ea7e3d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 279499c474d34255037df1d884266d7b0a3a2888f2551a8d61d2deb4a0c82edf72f4b7588c18cce3fae06cb581cf89d48cf1df2e2fd098e933e6f9e02c940398
|
7
|
+
data.tar.gz: f5ddcfbfd85609bdfbdf2e4fc772c81acabe4db8fd3138ac5247bfbfeb3c2236af5fdb59cc3f7342667e88844826c27df3b0128e1a2c13dfdc659a10e7a9db45
|
data/lib/flightcheck.rb
CHANGED
@@ -1,39 +1,79 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
|
3
3
|
class Flight
|
4
|
-
attr_reader :
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
|
4
|
+
attr_reader :flight_number, :departure_date, :title, :status, :route, :url, :raw_airline_iata, :airline_iata, :departure_airport, :arrival_airport
|
5
|
+
|
6
|
+
## Initialize
|
7
|
+
def initialize(flight_number, departure_date)
|
8
|
+
|
9
|
+
# Flight number
|
10
|
+
# e.g. "BA2589"
|
11
|
+
@flight_number = flight_number
|
12
|
+
|
13
|
+
# Departure date
|
14
|
+
# e.g. "2014-05-29"
|
15
|
+
@departure_date = departure_date
|
16
|
+
|
17
|
+
# FlightStats URL
|
18
|
+
@url = "http://www.flightstats.com/go/FlightStatus/flightStatusByFlight.do?airline=&flightNumber=#{flight_number}&departureDate=#{departure_date}"
|
13
19
|
end
|
14
20
|
|
21
|
+
## Use Mechanize to scrape all flight information
|
15
22
|
def check
|
23
|
+
|
24
|
+
# Instantiate a new Mechanize object
|
16
25
|
a = Mechanize.new
|
26
|
+
|
27
|
+
# Visit the flightstats URL to scrape information
|
17
28
|
a.get(@url) do |page|
|
29
|
+
|
30
|
+
# Page title contains the basic information for the flight
|
31
|
+
# e.g. "(BA) British Airways 2589 Flight Status"
|
18
32
|
@title = page.search("head > title").text.strip
|
33
|
+
|
34
|
+
# Flight status
|
35
|
+
# e.g. "Landed - Delayed 103 minutes"
|
19
36
|
@status = page.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.statusBlock > div.statusType").text.strip
|
20
|
-
end
|
21
37
|
|
22
|
-
|
23
|
-
|
38
|
+
# Flight route
|
39
|
+
# e.g. "(VCE) Venice, IT to (LGW) London, EN, GB"
|
40
|
+
@route = page.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.route").text.strip
|
41
|
+
|
42
|
+
end
|
24
43
|
|
25
44
|
## Airline IATA
|
26
|
-
# Extract raw airline iata and convert to string to avoid
|
45
|
+
# Extract raw airline iata and convert to string to avoid
|
27
46
|
# TypeError: no implicit conversion of MatchData intro String
|
28
47
|
@raw_airline_iata = /\(\w+\)/.match(@title).to_s
|
29
48
|
|
30
|
-
# Extract the airline IATA without the
|
49
|
+
# Extract the airline IATA without the parentheses
|
31
50
|
@airline_iata = /\w+/.match(@raw_airline_iata)
|
32
51
|
|
33
52
|
## Departure airport IATA
|
34
|
-
#
|
53
|
+
# @raw_departure_airport_iata = /\w+/.match(@route).to_s
|
35
54
|
|
36
55
|
## Arrival airport IATA
|
37
56
|
# Code here
|
57
|
+
|
58
|
+
## Flight route
|
59
|
+
# Cleanup the scraped route information
|
60
|
+
|
61
|
+
# Delete all "\t" from the string
|
62
|
+
@route.delete!("\t")
|
63
|
+
|
64
|
+
# Substitue all "\n\n" with " "
|
65
|
+
@route.gsub!("\n\n", " ")
|
66
|
+
|
67
|
+
# Substitue all "\n" with " "
|
68
|
+
@route.gsub!("\n", " ")
|
69
|
+
|
70
|
+
# Substitue all " " with " "
|
71
|
+
@route.gsub!(" ", " ")
|
72
|
+
|
73
|
+
## Information
|
74
|
+
# Print all relevant information to te console
|
75
|
+
puts @title
|
76
|
+
puts @status
|
77
|
+
puts @route
|
38
78
|
end
|
39
|
-
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flightcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Narek Aramjan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|