from CSAir import *
import sys
graph = load_initial_json()
print("Welcome to the CSAir query interface! Type help for commands!\n")
command_list = "Command list:\n" \
"help: Displays this command list.\n" \
"exit: Closes the query interface.\n" \
"list: Lists cities with CSAir routes.\n" \
"continents: Displays a list of continents and cities with CSAir routes.\n" \
"lookup <code>: View detailed information of a location.\n" \
"showmap: Show the map of the routes at http://www.gcmap.com.\n" \
"stats: Displays various statistics.\n" \
"hubs: Displays the hub cities.\n" \
"\n" \
"remove city: Delete a city.\n" \
"remove route: Delete a route.\n" \
"add city: Add a city.\n" \
"add route: Add a route.\n" \
"edit <code>: Edit an existing city.\n" \
"\n" \
"save <filename>: Save the data to a file.\n" \
"merge <filename>: Load new data and combine it with current data.\n" \
"\n" \
"route info: Specify a route to display total distance, cost, and time.\n" \
"route shortest: Generate the shortest route between two cities and display the route information.\n" \
"\n" \
"server: Start the web server.\n"
prompt = ">"
print(command_list)
print("\n" + prompt, end="")
for line in sys.stdin:
line = line.rstrip('\n')
if line == "help":
print(command_list)
elif line == "list":
list_locations(graph)
elif line[:7] == "lookup ":
print(lookup(graph, line[7:]))
elif line == "showmap":
url = generate_map_url(graph)
show_map(url)
elif line == "stats":
print(print_longest(graph))
print(print_shortest(graph))
print(print_average(graph))
print(print_smallest_city(graph))
print(print_largest_city(graph))
print(print_average_city(graph))
elif line == "continents":
print(print_continents(graph))
elif line == "hubs":
print(print_hubs(graph))
elif line == "add city":
add_city(graph)
elif line == "add route":
add_route(graph)
elif line == "remove city":
remove_city(graph)
elif line == "remove route":
remove_route(graph)
elif line[:5] == "edit ":
edit_city(graph, line[5:])
elif line[:5] == "save ":
save_json(graph, line[5:])
elif line[:6] == "merge ":
merge_json(graph, line[6:])
elif line == "route info":
route_info(graph)
elif line == "route shortest":
route_shortest(graph)
elif line == "exit":
break
else:
print("Invalid command, type 'help' for commands.")
print("\n" + prompt, end="")
print("Closing query!")