-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAltair.rb
97 lines (81 loc) · 2.28 KB
/
Altair.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
97
#!usr/bin/ruby
# Made With <3
require 'open-uri'
require 'uri'
require 'json'
require 'pp'
include Math
# Get Input
inLAT = gets.chomp
inLNG = gets.chomp
# Flights in a radius of 5 Miles
LATFinalM = (inLAT.to_f - 0.0727)
LATFinalP = (inLAT.to_f + 0.0727)
LNGFinalM = (inLNG.to_f - 0.0727)
LNGFinalP = (inLNG.to_f + 0.0727)
#Feed
FeedURL = "http://bma.data.fr24.com/zones/fcgi/feed.json?array=1&bounds=" + LATFinalP.round(4).to_s + "," + LATFinalM.round(4).to_s + "," + LNGFinalM.round(4).to_s + "," + LNGFinalP.round(4).to_s
feedSrc = open(FeedURL).read
#Weather URL
WeatherURL = "http://api.apixu.com/v1/current.json?key=8fdb3e76a592483a86d164951162304&q=" + inLAT + "," + inLNG
WeatherSrc = open(WeatherURL).read
# Wind Speed
SWindSpeed = "\"wind_kph\":"
EWindSpeed = ","
WindSpeed = WeatherSrc[/#{SWindSpeed}(.*?)#{EWindSpeed}/m, 1]
# Wind Degree
SWindDeg = "\"wind_degree\":"
EWindDeg = ","
WindDeg = WeatherSrc[/#{SWindDeg}(.*?)#{EWindDeg}/m, 1]
# Wind Direction
SWindDir = "\"wind_dir\":"
EWindDir = ","
WindDir = WeatherSrc[/#{SWindDir}(.*?)#{EWindDir}/m, 1]
# Temperature
STemp = "\"temp_c\":"
ETemp = ","
Temp = WeatherSrc[/#{STemp}(.*?)#{ETemp}/m, 1]
# Pressure
SPressure = "\"pressure_mb\":"
EPressure = ","
Pressure = WeatherSrc[/#{SPressure}(.*?)#{EPressure}/m, 1]
# Humidity
SHumidity = "\"humidity\":"
EHumidity = ","
Humidity = WeatherSrc[/#{SHumidity}(.*?)#{EHumidity}/m, 1]
# Clouds
SCloud = "\"cloud\":"
ECloud = ","
Cloud = WeatherSrc[/#{SCloud}(.*?)#{ECloud}/m, 1]
# Create json File
fJson = File.open("Altair.json","w")
all = feedSrc.split('[[')[1]
record = all.split('[')
record.each do |value|
lat = value.split(',')[2]
lng = value.split(',')[3]
theta = value.split(',')[4]
height = value.split(',')[5]
height_f = height.to_f * 0.3048
speed = value.split(',')[6]
speed_f = speed.to_f * 1.852
tempHash = {
"lat" => lat,
"lng" => lng,
"x" => ((lat.to_f - inLAT.to_f) * 111.045).round(4),
"y" => ((lng.to_f - inLNG.to_f) * 111.045).round(4),
"theta" => theta,
"height" => height_f.round(2).to_s,
"speed" => speed_f.round(2).to_s,
"temperature" => Temp,
"pressure" => Pressure,
"WindDir" => WindDir,
"WindDeg" => WindDeg,
"WindSpeed" => WindSpeed,
"humidity" => Humidity,
"cloud" => Cloud
}
fJson.write(tempHash)
fJson.write("\n")
end
fJson.close