-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummary.py
executable file
·79 lines (68 loc) · 2.05 KB
/
summary.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
#!/usr/bin/python3
import json
import scraper
from datetime import datetime, timedelta
import requests
import sys
import webhook
import time
import schedule
import traceback
config = json.load(open("config.json", "r"))
headers = {
"accept-encoding": "gzip, br",
"accept-language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
"cache-control": "max-age=0",
"origin": "https://www.flightradar24.com",
"referer": "https://www.flightradar24.com/",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
}
def start():
schedule.every().day.at("23:00").do(run)
run()
while True:
schedule.run_pending()
try:
time.sleep(600)
except KeyboardInterrupt:
exit(130)
def run():
try:
_run()
except Exception:
traceback.print_exc()
def _run(delta=0):
webhook.clear()
date = datetime.now().strftime(r"%d %m, %H:%M:%S")
flights = []
sys.stdout.flush()
for index, registration in enumerate(config["planes"]):
flights.extend(scraper.getFlights(registration.lower(),
datetime.now().date() + timedelta(days=delta)))
print(
f"\r[{date}] checking {index+1} of {len(config['planes'])}: {registration} ({round((index+1) / len(config['planes']) * 100)}%)",
end="",
)
sys.stdout.flush()
time.sleep(5) # ratelimit
print()
print(f"got {len(flights)} flights", end="")
sys.stdout.flush()
for flight in flights:
res = requests.get(
f"https://data-live.flightradar24.com/clickhandler/?version=1.5&flight={flight}",
headers=headers,
)
res.raise_for_status()
webhook.generateEmbed("✈️ FLight", res.json())
webhook.sendMessage()
print()
if __name__ == "__main__":
if len(sys.argv) < 1:
delta = 0
else:
delta = int(sys.argv[1])
_run(delta=delta)