-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyState.py
152 lines (123 loc) · 3.53 KB
/
PyState.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import urllib.request
import json
from enum import Enum
# Dining Locations
class DiningLocations(Enum):
CONVERSATIONS_DINING = 1
UNION_DRIVE_MARKETPLACE = 4
WEST_SIDE_MARKET = 5
SOUTH_SIDE_MARKET = 7
EAST_SIDE_MARKET = 10
BUSINESS_CAFE = 11
CLYDES_FRESH_EXPRESS = 12
COURTYARD_CAFE = 13
DESIGN_CAFE = 14
GENTLE_DOCTOR_CAFE = 15
HAWTHORN = 16
HUB_GRILL_CAFE = 17
CARIBOU_COFFEE = 18
ABE_HARVEST_CAFE = 30
FROOTS = 26
MEMORIAL_UNION_FOOD_COURT = 19
BOOKENDS_CAFE = 21
MU_MARKET_CAFE = 21
SEASONS_MARKETPLACE = 24
STORMS_DINING = 25
GLOBAL_CAFE = 28
FILEY_WINDOWS = 31
LANCE_AND_ELLIES = 32
# Meal Types
class MealTypes(Enum):
BREAKFAST = "Breakfast"
LUNCH = "Lunch"
DINNER = "Dinner"
LATE_NIGHT = "Late Night"
BAR_ONLY = "Deli/Salad Bar Only"
CONTINUOUS_SERVICE = "Continuous Services"
# Laundry Rooms
class LaundryRoomLocations(Enum):
BARTON = "Barton"
BUCHANAN = "Buchanan"
EATON1 = "Eaton%201"
EATON2 = "Eaton%202"
EATON3 = "Eaton%203"
EATON4 = "Eaton%204"
ELM = "Elm"
FREEMAN = "Freeman"
FRILEY175A = "Friley%20175A"
FRIELY84A = "Friley%2084A"
GEOFFROY = "Geoffroy"
HELSER = "Helser"
LARCH = "Larch"
LINDEN = "Linden"
LYON = "Lyon"
MAPLE = "Maple"
# MyState and NextBus endpoints.
isu_cyride_prediction_endpoint = "http://webservices.nextbus.com/service/publicJSONFeed?a=cyride&command=predictions&stopId="
isu_dining_hours_endpoint = "http://apps.dining.iastate.edu/mystate-api/1.0/hours/"
isu_dining_menu_endpoint = "http://apps.dining.iastate.edu/mystate-api/1.0/menu/"
isu_dining_information_endpoint = "http://apps.dining.iastate.edu/mystate-api/1.0/"
isu_laundry_endpoint="https://www.laundryalert.com/cgi-bin/backoffice/MachineState.py?format=JSON&loc=isulaundry&room="
# Remove duplicates in the lists.
def remove_duplicates(values):
output = []
seen = set()
for value in values:
if value not in seen:
output.append(value)
seen.add(value)
return output
# Removes invalid characters from menus.
def remove_invalids(values):
output = []
for value in values:
if value != "-":
output.append(value)
return output
# Retrieves JSON from a REST web service.
def get_JSON(url):
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
return json.loads(response.read())
# Gets food items from a specific dining location, and specific time.
def get_food_items(place, type):
food_items = []
data = get_JSON(isu_dining_menu_endpoint + str(place.value))
for object in data:
if object["event"] == str(type.value):
item = object["item_main"]
station = object["station"]
#final = item + " - " + station
final = item
food_items.append(final)
# TODO Does not remove duplicates.
food_items = remove_duplicates(food_items)
food_items = remove_invalids(food_items)
if len(food_items) != 0:
print(*food_items, sep='\n')
else:
print("None")
return food_items
# Gets dining hours for a specific dining location.
def get_dining_hours(place, type):
data = get_JSON(isu_dining_hours_endpoint + str(place.value))
hours = ""
for object in data:
if object["name"] == str(type.value):
hours = object["hours"]
print(hours)
return hours
def get_laundry(building):
data = get_JSON(isu_laundry_endpoint + str(building.value))
for object in data["location"]["rooms"][0]["machines"]:
#print(object)
print(object["port"])
print(object["description"])
print(object["status"])
print(object["timeRemaining"])
print("\n")
# TODO Get bus times.
def get_bus_times(stop_id):
times = []
data = get_JSON(isu_cyride_prediction_endpoint + str(stop_id))
print("Stubbed!")