-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullflight.py
100 lines (82 loc) · 3.59 KB
/
fullflight.py
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
98
99
100
from math import radians, sin, cos, atan2, sqrt, degrees, pow
import windowseat
import re, requests
import sys
from math import atan2, degrees
import threading
from subprocess import run
def create_flight_path(start, end, start_bearing, end_bearing, num_points):
# Calculate the distance and bearing between the two points
lat1, lon1 = start
lat2, lon2 = end
dlat = radians(lat2 - lat1)
dlon = radians(lon2 - lon1)
a = sin(dlat/2)**2 + cos(radians(lat1)) * cos(radians(lat2)) * sin(dlon/2)**2
c = 2 * atan2(sqrt(a), sqrt(1-a))
distance = 1000 * 6371 * c # convert distance to meters
bearing = atan2(sin(dlon) * cos(radians(lat2)), cos(radians(lat1)) * sin(radians(lat2)) - sin(radians(lat1)) * cos(radians(lat2)) * cos(dlon))
bearing = (degrees(bearing) + 360) % 360
# Adjust the bearing for the runway headings
bearing = (bearing + start_bearing) % 360
end_bearing = (end_bearing + 180) % 360
# Generate the flight path coordinates
coords = []
altitudes = []
for i in range(num_points):
frac = i / (num_points - 1)
lat = lat1 + frac * (lat2 - lat1)
lon = lon1 + frac * (lon2 - lon1)
coords.append((lat, lon, bearing))
bearing = (bearing + (end_bearing - start_bearing) / (num_points - 1)) % 360
return coords
def get_airport_info(airport,endport):
# Construct the URL for the airport's AirNav page
url = f"https://www.airnav.com/airport/{airport}"
# Make a GET request to the URL and extract the page content
response = requests.get(url)
content = response.content.decode("utf-8")
# Extract the latitude and longitude from the page content
start,end = windowseat.get_db(airport,endport)
# Use regex to find all instances of "x magnetic, y true"
heading_pattern = r"(\d+) magnetic, (\d+) true"
heading_matches = re.findall(heading_pattern, content)
# Extract the true headings from the matches
true_heading_start = [int(match[1]) for match in heading_matches][0]
url = f"https://www.airnav.com/airport/{endport}"
response = requests.get(url)
content = response.content.decode("utf-8")
heading_pattern = r"(\d+) magnetic, (\d+) true"
heading_matches = re.findall(heading_pattern, content)
# Extract the true headings from the matches
true_heading_end = [int(match[1]) for match in heading_matches][0]
# Make a GET request to the URL and extract the page content
# Return a dictionary with the latitude, longitude, and true headings
airport_info = {
"start": start,
"end": end,
"true_headings": [true_heading_start,true_heading_end]
}
return airport_info
ainfo = get_airport_info(sys.argv[1], sys.argv[2])
print(ainfo)
start = ainfo["start"][::-1]
end = ainfo["end"][::-1]
time = int(sys.argv[3])
fps = int(sys.argv[4])
left = "l" in sys.argv[5]
count = time * fps
flight_path = create_flight_path(start, end, 101,121,count)
bearing_addition = 90
if left:
bearing_addition -= 180
threads = []
for c,i in enumerate(flight_path):
zoom_level = 17
t = threading.Thread(target=windowseat.get_photo, args=((i[1],i[0]),zoom_level,open("mapboxkey").read().splitlines()[0],i[2]+bearing_addition,f"photos/{c:04n}"))
threads.append(t)
t.start()
for t in threads:
t.join()
code = run(f"ffmpeg -framerate {fps} -i 'photos/%04d.jpg' flight.mp4; rm photos/*.jpg".split(" "))
if code.returncode != 0:
print(f"command 'ffmpeg -framerate {fps} -i 'photos/%04d.jpg' flight.mp4; rm photos/*.jpg' returned an non-zero return code. Make sure you have ffmpeg installed.")