-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapquest_input.py
More file actions
106 lines (83 loc) · 3.64 KB
/
mapquest_input.py
File metadata and controls
106 lines (83 loc) · 3.64 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'''
MapQuest User Interaction Input
---
A module that reads the input and constructs the objects that will generate the program's output.
This is the only module that should have an if __name__ == '__main__': block to make it executable,
you would execute this module.
---
The program should not prompt the user in any way, it should simply read whatever input is
typed into the console while assuming that the user knows the precise input format:
(1) An integer whose value is at least 2, alone on a line, that specifies how many locations
the trip will consist of.
(2) If there are N locations, the next N lines of input will describe a location. Each location
can be a CITY such as Irvine, CA, an ADDRESS such as 4545 Campus Dr, Irvine, CA, or
ANYTHING the MapQuest API will accept as a location.
(3) A positive integer whose value is at least 1, alone on a line, that specifies how many
outputs that need to be generated.
(4) If there are M outputs, the next M lines of input will describe an output which can be of
the following:
STEPS for step-by-step directions and a brief description of each maneuver (e.g. a turn,
entering/exiting a freeway, etc.).
TOTALDISTANCE for the total distance traveled if completing the entire trip.
TOTALTIME for the total estimated time to complete the entire trip.
LATLONG for the latitude and longitude of each of the locations specified in the input.
'''
import mapquest_api
import mapquest_output
def trip_locations() -> int:
'''
Asks user for input of how many locations they want and returns an integer if it is greater than 1.
'''
try:
number_of_locations = int(input())
assert (number_of_locations > 1) == True
return number_of_locations
except:
print('The number of locations must be greater than 1. Please try again.')
return trip_locations()
def location_descriptions(n: int) -> list:
'''
Asks user for input of the descriptions of the desired locations and returns a list of locations.
'''
locations = []
while n > 0:
description = str(input())
locations.append(description)
n -= 1
return locations
def program_outputs() -> int:
'''
Asks user for input of how many outputs they want and returns an integer if it is greater than 0.
'''
try:
number_of_outputs = int(input())
assert (number_of_outputs > 0) == True
return number_of_outputs
except:
print('The number of outputs must be greater than 0. Please try again.')
return program_outputs()
def output_descriptions(n: int) -> list:
'''
Asks user for input of what type of outputs they want and returns a list of output instructions.
'''
descriptions = [ 'STEPS', 'TOTALDISTANCE', 'TOTALTIME', 'LATLONG' ]
outputs = []
while n > 0:
instruction = str(input())
if instruction in descriptions:
outputs.append(instruction)
n -= 1
else:
print('Invalid output type. Please try again.')
continue
print()
return outputs
if __name__ == '__main__':
number_of_locations = trip_locations()
route = location_descriptions(number_of_locations)
number_of_outputs = program_outputs()
instructions = output_descriptions(number_of_outputs)
mapquest_url = mapquest_api.build_route_url(route)
json_format = mapquest_api.http_request(mapquest_url)
mapquest_output.print_map(instructions, json_format)
print('Directions Courtesy of MapQuest; Map Data Copyright OpenStreetMap Contributors.')