#!/usr/bin/env python3
import fetch_stations as f
import file_io as io

# url for all weather stations.
URL = "https://apex.oracle.com/pls/apex/raspberrypi/weatherstation/getallstations"
STATION_URL = 'https://apex.oracle.com/pls/apex/raspberrypi/weatherstation/getlatestmeasurements/'
STATION = 'KALN'
STATIONS_URL = STATION_URL + STATION

# LAT, LON Data for the haversine example
H_LAT = 38.9208333
H_LON = -90.1830556
S_LAT = 53.317
S_LON = -3.46

# Call the get_stations function.
all_stations = f.get_stations(URL)

# write the all_stations data to a file
io.write_json_data('stations.json', str(all_stations))

# Haversine example
station_dist = f.haversine(H_LON, H_LAT, S_LON, S_LAT)

# gets the closest station to the home LAT, LON
clossest_station = []
the_closest = f.closet_station(all_stations, H_LON, H_LAT, clossest_station)
close_station = min(clossest_station)

# Using the close_station id, gets the weather from the station
local_wx_url = STATION_URL + str(the_closest)
local_wx = f.get_stations(local_wx_url)
print(local_wx)

f.pretty_print(local_wx)

