-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_for_track_script.py
More file actions
47 lines (36 loc) · 1.61 KB
/
check_for_track_script.py
File metadata and controls
47 lines (36 loc) · 1.61 KB
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
import json
import requests
'''
The purpose of this script is to perform a simple check if the cruise ID from
user input has a track or not. (1) prompts the user in the terminal "What is your
cruise ID?" (2) once the user inputs a number either returns "Cruise ID: ### has
no cruise track" or "Cruise ID: ### has a cruise track"
'''
END_POINT = "https://cchdo.ucsd.edu/api/v1/cruise"
API_KEY = ""
def get_cruise_json():
#requests all cruise info from END_POINT and creates dictionary of all cruise ids
r = requests.get(END_POINT)
cruise_dict = {cruise["id"]:cruise["expocode"] for cruise in r.json()['cruises']}
return cruise_dict
def get_user_cruise(cruise_dict):
user_cruise = input("What is your cruise ID (e.g. '1217')? \n")
#check to make sure the cruise is a number and an existing cruise
if (not user_cruise.isdigit()) and (user_cruise not in cruise_dict.values()):
print("Please enter a valid cruise from https://cchdo.ucsd.edu/api/v1/cruise")
quit()
return user_cruise
def find_non_tracked(user_cruise):
#requests json for cruise from user input and checks if track exists
t = requests.get(END_POINT + "/" + str(user_cruise))
cruise_object = t.json()
cruise_track = cruise_object["geometry"]["track"]
if len(cruise_track) == 0:
print("Cruise ID: " + str(user_cruise) + " has no cruise track")
else:
print("Cruise ID: " + str(user_cruise) + " has a cruise track")
if __name__ == "__main__":
r = ''
cruise_dict = get_cruise_json()
user_cruise = get_user_cruise(cruise_dict)
no_tracks_output = find_non_tracked(user_cruise)