Add flags for things, separate the spooky matrix stuff, formatting.
Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
This commit is contained in:
		
							
								
								
									
										185
									
								
								naut.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										185
									
								
								naut.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@@ -1,5 +1,4 @@
 | 
				
			|||||||
# !/usr/bin/python
 | 
					#! /usr/bin/python
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from math import radians, cos, sin, asin, sqrt
 | 
					from math import radians, cos, sin, asin, sqrt
 | 
				
			||||||
import numpy as np
 | 
					import numpy as np
 | 
				
			||||||
@@ -9,21 +8,20 @@ import time
 | 
				
			|||||||
import json
 | 
					import json
 | 
				
			||||||
from time import strftime
 | 
					from time import strftime
 | 
				
			||||||
import random
 | 
					import random
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					import argparse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# haversine function to determine distance between two lat,long points
 | 
					# haversine function to determine distance between two lat,long points
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def haversine(lat1, lon1, lat2, lon2):
 | 
					def haversine(lat1, lon1, lat2, lon2):
 | 
				
			||||||
    R = 3959.87433  # earth radius in miles
 | 
					    R = 3959.87433  # earth radius in miles
 | 
				
			||||||
    dLat = radians(lat2 - lat1)
 | 
					    dLat = radians(lat2 - lat1)
 | 
				
			||||||
    dLon = radians(lon2 - lon1)
 | 
					    dLon = radians(lon2 - lon1)
 | 
				
			||||||
    a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2
 | 
					    a = sin(dLat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dLon / 2) ** 2
 | 
				
			||||||
    c = 2*asin(sqrt(a))
 | 
					    c = 2 * asin(sqrt(a))
 | 
				
			||||||
    return R*c
 | 
					    return R * c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# get a random enough number
 | 
					# get a random enough number
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def getfloat():
 | 
					def getfloat():
 | 
				
			||||||
    output = random.random()
 | 
					    output = random.random()
 | 
				
			||||||
    return output
 | 
					    return output
 | 
				
			||||||
@@ -34,27 +32,24 @@ def str_time_prop(start, end, format, prop):
 | 
				
			|||||||
    stime = start
 | 
					    stime = start
 | 
				
			||||||
    etime = end
 | 
					    etime = end
 | 
				
			||||||
    ptime = stime + prop * (etime - stime)
 | 
					    ptime = stime + prop * (etime - stime)
 | 
				
			||||||
 | 
					 | 
				
			||||||
    return time.strftime(format, time.localtime(ptime))
 | 
					    return time.strftime(format, time.localtime(ptime))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# get random time in the future
 | 
					# get random time in the future
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def random_date(start, end, prop):
 | 
					def random_date(start, end, prop):
 | 
				
			||||||
    return str_time_prop(start, end, '%m/%d/%Y %I:%M%p', prop)
 | 
					    return str_time_prop(start, end, "%m/%d/%Y %I:%M%p", prop)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# function to generate a lat,long coordinate within a range
 | 
					# function to generate a lat,long coordinate within a range
 | 
				
			||||||
# inspiration from this post:
 | 
					# inspiration from this post:
 | 
				
			||||||
# https://gis.stackexchange.com/questions/25877/generating-random-locations-nearby
 | 
					# https://gis.stackexchange.com/questions/25877/generating-random-locations-nearby
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def create_random_point(x0, y0, distance):
 | 
					def create_random_point(x0, y0, distance):
 | 
				
			||||||
    # approximately 1609 meters in a mile
 | 
					    # approximately 1609 meters in a mile
 | 
				
			||||||
    # 5 miles = about 8045
 | 
					    # 5 miles = about 8045
 | 
				
			||||||
    # 111300 = meters in a degree
 | 
					    # 111300 = meters in a degree
 | 
				
			||||||
    # 69 = miles in a degree
 | 
					    # 69 = miles in a degree
 | 
				
			||||||
    r = distance / 111300
 | 
					    r = distance / 111300
 | 
				
			||||||
    r = r/2
 | 
					    r = r / 2
 | 
				
			||||||
    u = float(getfloat())
 | 
					    u = float(getfloat())
 | 
				
			||||||
    v = float(getfloat())
 | 
					    v = float(getfloat())
 | 
				
			||||||
    w = r * np.sqrt(u)
 | 
					    w = r * np.sqrt(u)
 | 
				
			||||||
@@ -62,9 +57,37 @@ def create_random_point(x0, y0, distance):
 | 
				
			|||||||
    x = w * np.cos(t)
 | 
					    x = w * np.cos(t)
 | 
				
			||||||
    x1 = x / np.cos(y0)
 | 
					    x1 = x / np.cos(y0)
 | 
				
			||||||
    y = w * np.sin(t)
 | 
					    y = w * np.sin(t)
 | 
				
			||||||
    print("u="+str(u))
 | 
					    return (x0 + x1, y0 + y)
 | 
				
			||||||
    print("v="+str(v))
 | 
					
 | 
				
			||||||
    return (x0+x1, y0+y)
 | 
					
 | 
				
			||||||
 | 
					def spooky_print(message):
 | 
				
			||||||
 | 
					    for character in message:
 | 
				
			||||||
 | 
					        print(character, end="", flush=True)
 | 
				
			||||||
 | 
					        time.sleep(0.3)
 | 
				
			||||||
 | 
					    print("\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def white_rabbit(future_time, latitude, longitude):
 | 
				
			||||||
 | 
					    # homage to the Matrix
 | 
				
			||||||
 | 
					    init1_msg = "Wake up, Neo..."
 | 
				
			||||||
 | 
					    init_msg = "The Matrix has you..."
 | 
				
			||||||
 | 
					    rabbit_msg1 = "follow the"
 | 
				
			||||||
 | 
					    rabbit_msg2 = "white rabbit..."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    os.system("clear")
 | 
				
			||||||
 | 
					    spooky_print(init1_msg)
 | 
				
			||||||
 | 
					    time.sleep(5)
 | 
				
			||||||
 | 
					    os.system("clear")
 | 
				
			||||||
 | 
					    spooky_print(init_msg)
 | 
				
			||||||
 | 
					    time.sleep(5)
 | 
				
			||||||
 | 
					    os.system("clear")
 | 
				
			||||||
 | 
					    spooky_print(rabbit_msg1)
 | 
				
			||||||
 | 
					    spooky_print("    " + rabbit_msg2)
 | 
				
			||||||
 | 
					    time.sleep(5)
 | 
				
			||||||
 | 
					    os.system("clear")
 | 
				
			||||||
 | 
					    spooky_print(" " + future_time)
 | 
				
			||||||
 | 
					    spooky_print(" " + latitude)
 | 
				
			||||||
 | 
					    spooky_print(" " + longitude)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
init_start = time.time()
 | 
					init_start = time.time()
 | 
				
			||||||
@@ -73,67 +96,89 @@ newplot = ()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
##### User defined variables #####
 | 
					##### User defined variables #####
 | 
				
			||||||
 | 
					
 | 
				
			||||||
loghandle = './naut.log'
 | 
					loghandle = "./naut.log"
 | 
				
			||||||
logfile = open(loghandle, "a")
 | 
					logfile = open(loghandle, "a")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# home_base (starting point), set to Warsaw center.
 | 
					parser = argparse.ArgumentParser()
 | 
				
			||||||
latitude1, longitude1 = 52.229832, 21.011734
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#window_secs = 10800
 | 
					parser.add_argument("-x", "--matrix", action="store_true", help="toggle the matrix")
 | 
				
			||||||
window_secs = 1800
 | 
					parser.add_argument(
 | 
				
			||||||
 | 
					    "-c",
 | 
				
			||||||
 | 
					    "--coordinates",
 | 
				
			||||||
 | 
					    nargs=2,
 | 
				
			||||||
 | 
					    action="append",
 | 
				
			||||||
 | 
					    help="enter lat and long for home base, defaults to 52.229832 21.011734",
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					parser.add_argument(
 | 
				
			||||||
 | 
					    "-t", "--window", type=int, help="set the time window in minutes, defaults to 30"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					parser.add_argument(
 | 
				
			||||||
 | 
					    "-m",
 | 
				
			||||||
 | 
					    "--distance",
 | 
				
			||||||
 | 
					    type=int,
 | 
				
			||||||
 | 
					    help="set the radius from home base in meters, defaults to 4827",
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# home_base (starting point), set to Warsaw center.
 | 
				
			||||||
 | 
					if args.coordinates:
 | 
				
			||||||
 | 
					    latitude1, longitude1 = float(args.coordinates[0][0]), float(args.coordinates[0][1])
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    latitude1, longitude1 = 52.229832, 21.011734
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if args.window:
 | 
				
			||||||
 | 
					    window_secs = args.window * 60
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    window_secs = 1800
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# how far to travel in meters from home base
 | 
					# how far to travel in meters from home base
 | 
				
			||||||
meters_out = 4827
 | 
					if args.distance:
 | 
				
			||||||
 | 
					    meters_out = args.distance
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    meters_out = 4827
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### End User Defined variables #####
 | 
					##### End User Defined variables #####
 | 
				
			||||||
 | 
					
 | 
				
			||||||
current_time = time.time()
 | 
					current_time = time.time()
 | 
				
			||||||
window = current_time + window_secs
 | 
					window = current_time + window_secs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# for loop to get multiple points if desired (for future development - void/attractor calculations)
 | 
					timex = float(getfloat())
 | 
				
			||||||
for i in range(1, 2):
 | 
					x, y = create_random_point(latitude1, longitude1, meters_out)
 | 
				
			||||||
    timex = float(getfloat())
 | 
					future_time = random_date(current_time, window, timex)
 | 
				
			||||||
    x, y = create_random_point(latitude1, longitude1, meters_out)
 | 
					dest_lat = str(format(x, ".5f"))
 | 
				
			||||||
    future_time = random_date(current_time, window, timex)
 | 
					dest_long = str(format(y, ".5f"))
 | 
				
			||||||
    dest_lat = str(format(x, '.5f'))
 | 
					orig_lat = str(latitude1)
 | 
				
			||||||
    dest_long = str(format(y, '.5f'))
 | 
					orig_long = str(longitude1)
 | 
				
			||||||
    orig_lat = str(latitude1)
 | 
					newplot = (x, y)
 | 
				
			||||||
    orig_long = str(longitude1)
 | 
					origplot = (latitude1, longitude1)
 | 
				
			||||||
    newplot = (x, y)
 | 
					dist = haversine(origplot[0], origplot[1], newplot[0], newplot[1])
 | 
				
			||||||
    origplot = (latitude1, longitude1)
 | 
					dist = str(format(dist, ".2f"))
 | 
				
			||||||
    dist = haversine(origplot[0], origplot[1], newplot[0], newplot[1])
 | 
					logfile.write(
 | 
				
			||||||
    dist = str(format(dist, '.2f'))
 | 
					    dtime
 | 
				
			||||||
    print("Distance between points is ", dist)
 | 
					    + " homebase_lat="
 | 
				
			||||||
    print("destination: "+dest_lat+" "+dest_long)
 | 
					    + orig_lat
 | 
				
			||||||
    print("future_time: "+future_time)
 | 
					    + " homebase_long="
 | 
				
			||||||
    logfile.write(dtime+" homebase_lat="+orig_lat+" homebase_long="+orig_long+" dest_lat=" +
 | 
					    + orig_long
 | 
				
			||||||
                  dest_lat+" dest_long="+dest_long+" future_time="+future_time+" dist="+dist)
 | 
					    + " dest_lat="
 | 
				
			||||||
 | 
					    + dest_lat
 | 
				
			||||||
 | 
					    + " dest_long="
 | 
				
			||||||
 | 
					    + dest_long
 | 
				
			||||||
 | 
					    + " future_time="
 | 
				
			||||||
 | 
					    + future_time
 | 
				
			||||||
 | 
					    + " dist="
 | 
				
			||||||
 | 
					    + dist
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					logfile.write("\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    msg_breaker = '~'
 | 
					if args.matrix:
 | 
				
			||||||
    msg_space = '`'
 | 
					    white_rabbit(future_time, dest_lat, dest_long)
 | 
				
			||||||
    msg_space2 = '```'
 | 
					 | 
				
			||||||
    # homage to the Matrix
 | 
					 | 
				
			||||||
    init1_msg = 'Wake up, Neo...'
 | 
					 | 
				
			||||||
    init_msg = 'The Matrix has you..'
 | 
					 | 
				
			||||||
    rabbit_msg1 = 'follow the'
 | 
					 | 
				
			||||||
    rabbit_msg2 = 'white rabbit...'
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logfile.write("\n")
 | 
					print(
 | 
				
			||||||
    print(init1_msg)
 | 
					    "https://www.google.com/maps/search/?api=1&query="
 | 
				
			||||||
    time.sleep(5)
 | 
					    + dest_lat
 | 
				
			||||||
    print(msg_breaker)
 | 
					    + ","
 | 
				
			||||||
    print(init_msg)
 | 
					    + dest_long
 | 
				
			||||||
    time.sleep(5)
 | 
					    + "  Time: "
 | 
				
			||||||
    print(msg_breaker)
 | 
					    + future_time
 | 
				
			||||||
    print(rabbit_msg1)
 | 
					)
 | 
				
			||||||
    print(msg_breaker)
 | 
					 | 
				
			||||||
    print(msg_space2)
 | 
					 | 
				
			||||||
    print(rabbit_msg2)
 | 
					 | 
				
			||||||
    time.sleep(5)
 | 
					 | 
				
			||||||
    print(msg_breaker)
 | 
					 | 
				
			||||||
    print(" "+future_time)
 | 
					 | 
				
			||||||
    print(msg_breaker)
 | 
					 | 
				
			||||||
    print(" "+dest_lat)
 | 
					 | 
				
			||||||
    print(msg_space)
 | 
					 | 
				
			||||||
    print(dest_long)
 | 
					 | 
				
			||||||
    print("https://www.google.com/maps/search/?api=1&query="+dest_lat+","+dest_long+"  Time: "+future_time)
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user