-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (40 loc) · 1.46 KB
/
main.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
from fetch.Scraper import Scraper
from fetch.Sender import Sender
import json
import time
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--p", type=int, help="To print the fetched ships' data to the screen enter 0, to send the data to the localhost:UDP_PORT enter 1", default=0)
parser.add_argument("--socket",
help="UDP socket", type=int, default=5005)
parser.add_argument("--lat-min", type=float,
help="Minimum latitude", required=True)
parser.add_argument("--lat-max", type=float,
help="Maximum latitude", required=True)
parser.add_argument("--lon-min", type=float,
help="Minimum longitude", required=True)
parser.add_argument("--lon-max", type=float,
help="Maximum longitude", required=True)
args = parser.parse_args()
scraper = Scraper(latitude=(args.lat_min, args.lat_max),
longitude=(args.lon_min, args.lon_max))
sender = Sender("localhost", args.socket)
mode = args.p
def print_data(data: list[dict]):
for element in data:
print(element)
def send_data(data: list[dict]):
for ship in data:
message = json.dumps(ship)
sender.send(message)
print("sent: " + ship["SHIPNAME"])
time.sleep(0.1)
while True:
data: list[dict] = list()
data = scraper.get_ships()
print(f"{len(data)} ships are fetched.")
if mode:
send_data(data)
else:
print_data(data)