#!/opt/conda/bin/python3 import sys import math error_message = f'{sys.argv[0]}: invalid arguments' if len(sys.argv) != 3: print(error_message, file=sys.stderr) exit(1) try: point = tuple(math.radians(float(el)) for el in sys.argv[1:]) except ValueError: print(error_message, file=sys.stderr) exit(1) def great_circle_distance(point1, point2, radius=6371): long1, lat1 = point1 long2, lat2 = point2 distance = radius * math.acos( math.sin(lat1) * math.sin(lat2) + math.cos(lat1) * math.cos(lat2) * math.cos(long1 - long2) ) return round(distance) for line in sys.stdin: line = line.rstrip('\r\n') fields = line.split(';') long = math.radians(float(fields[5])) lat = math.radians(float(fields[6])) print(f'{line};{round(great_circle_distance(point, (long, lat)))}')