MouseTools 2.1.2.dev2__py3-none-any.whl → 3.0.0.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,400 +0,0 @@
1
- import requests
2
- from datetime import datetime, timedelta
3
- import pytz
4
- from .auth import get_headers
5
- from .parks import Park
6
- from .entertainments import Entertainment
7
- from .attractions import Attraction
8
- from .ids import WDW_PARK_IDS, DLR_PARK_IDS, WDW_ID, DLR_ID, DESTINATION_IDS, themeparkapi_ids
9
-
10
-
11
- class Destination(object):
12
-
13
- def __init__(self, id = None):
14
- """
15
- Constructor Function
16
- Allows access to various destination related data.
17
- """
18
- error = True
19
- self.__data = requests.get("https://api.wdpro.disney.go.com/facility-service/destinations/{}".format(id), headers=get_headers()).json()
20
- try:
21
- if self.__data['id'] is not None:
22
- error = False
23
- except:
24
- pass
25
-
26
- if error:
27
- raise ValueError('That destination is not available. id: ' + str(id) + '. Available destinations: {}'.format(", ".join(DESTINATION_IDS)))
28
-
29
- self.__id = id
30
- self.__name = self.__data['name']
31
- self.__entityType = self.__data['type']
32
-
33
- if self.__id == WDW_ID:
34
- self.__time_zone = pytz.timezone('US/Eastern')
35
- elif self.__id == DLR_ID:
36
- self.__time_zone = pytz.timezone('US/Pacific')
37
- else:
38
- self.__time_zone = pytz.utc
39
-
40
-
41
-
42
-
43
- def get_possible_ids(self):
44
- """Returns a list of possible ids of this entityType"""
45
- return DESTINATION_IDS
46
-
47
- def get_id(self):
48
- """Returns the id of the destination"""
49
- return self.__id
50
-
51
- def get_name(self):
52
- """Returns the name of the destination"""
53
- return self.__name
54
-
55
- def get_entityType(self):
56
- """Returns the entityType"""
57
- return self.__entityType
58
-
59
- def get_links(self):
60
- """Returns a dictionary of related links"""
61
- return self.__data['links']
62
-
63
- def get_time_zone(self):
64
- """Returns pytz timezone object"""
65
- return self.__time_zone
66
-
67
- def get_raw_data(self):
68
- """Returns the raw data from global-facility-service"""
69
- return self.__data
70
-
71
-
72
- def get_attraction_ids(self):
73
- """
74
- Returns a list of Attraction IDs
75
- """
76
- attractions = []
77
-
78
- data = requests.get(self.__data['links']['attractions']['href'], headers=get_headers()).json()
79
-
80
- for attract in data['entries']:
81
- try:
82
- attractions.append(attract['links']['self']['href'].split('/')[-1].split('?')[0])
83
- except:
84
- pass
85
- return attractions
86
-
87
- def get_entertainment_ids(self):
88
- """
89
- Returns a list of Entertainment IDs
90
- """
91
- entertainments = []
92
-
93
- data = requests.get(self.__data['links']['entertainments']['href'], headers=get_headers()).json()
94
-
95
- for enter in data['entries']:
96
- try:
97
- entertainments.append(enter['links']['self']['href'].split('/')[-1].split('?')[0])
98
- except:
99
- pass
100
- return entertainments
101
-
102
- def get_park_ids(self):
103
- """
104
- Returns a list of theme or water park IDs
105
- """
106
- ids = []
107
-
108
- data = requests.get(self.__data['links']['themeParks']['href'], headers=get_headers()).json()
109
-
110
- for entry in data['entries']:
111
- try:
112
- ids.append(entry['links']['self']['href'].split('/')[-1].split('?')[0])
113
- except:
114
- pass
115
-
116
- data = requests.get(self.__data['links']['waterParks']['href'], headers=get_headers()).json()
117
- try:
118
- if data['errors'] is not None:
119
- return ids
120
- except:
121
- pass
122
-
123
- for entry in data['entries']:
124
- try:
125
- ids.append(entry['links']['self']['href'].split('/')[-1].split('?')[0])
126
- except:
127
- pass
128
-
129
- return ids
130
-
131
- def get_entertainment_venue_ids(self):
132
- """
133
- Returns a list of Entertainment Venue IDs
134
- """
135
- entertainments = []
136
-
137
- data = requests.get(self.__data['links']['entertainmentVenues']['href'], headers=get_headers()).json()
138
-
139
- for enter in data['entries']:
140
- try:
141
- entertainments.append(enter['links']['self']['href'].split('/')[-1].split('?')[0])
142
- except:
143
- pass
144
- return entertainments
145
-
146
- def get_character_ids(self):
147
- """
148
- Returns a list of theme or water park IDs
149
- """
150
- ids = []
151
-
152
- data = requests.get("https://api.wdpro.disney.go.com/facility-service/characters", headers=get_headers()).json()
153
-
154
- for entry in data['entries']:
155
- try:
156
- ids.append(entry['links']['self']['href'].split('/')[-1].split('?')[0])
157
- except:
158
- pass
159
-
160
- return ids
161
-
162
- def get_themeparkapi_data(self):
163
- """Returns the list of dictionaries for all parks from the themeparks api"""
164
-
165
- all_data = []
166
-
167
- if self.__id == WDW_ID:
168
- parks = WDW_PARK_IDS
169
- else:
170
- parks = DLR_PARK_IDS
171
-
172
- for id in parks:
173
- try:
174
- park = themeparkapi_ids[id]
175
- all_data.extend(requests.get(f"https://api.themeparks.wiki/preview/parks/{park}/waittime").json())
176
- except:
177
- continue
178
-
179
- return all_data
180
-
181
-
182
- def get_wait_times(self):
183
- """Returns a list of dictionaries in the form of {rideid:time} for attractions and entertainments for this destination"""
184
- data = self.get_themeparkapi_data()
185
-
186
- times = {}
187
-
188
- for i in data:
189
- id = i['id'].split("_")[-1]
190
- try:
191
- if i['meta']['type'] != "RESTAURANT":
192
- times[id] = i['waitTime']
193
- except:
194
- times[id] = i['waitTime']
195
-
196
- return times
197
-
198
- def get_wait_times_detailed(self):
199
- """Returns a list of dictionaries in the form of {rideid:{name, status, wait_time}} for attractions and entertainments for this destination"""
200
- data = self.get_themeparkapi_data()
201
-
202
- times = {}
203
-
204
- for i in data:
205
- id = i['id'].split("_")[-1]
206
- this = {}
207
- try:
208
- if i['meta']['type'] != "RESTAURANT":
209
-
210
- update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ")
211
- update_time = update_time.replace(tzinfo=pytz.utc)
212
- update_time = update_time.astimezone(self.__time_zone)
213
-
214
- this['name'] = i['name']
215
- this['status'] = i['status']
216
- this['wait_time'] = i['waitTime']
217
- this['last_updated'] = update_time
218
- this['entityType'] = i['meta']['type'].capitalize()
219
- times[id] = this
220
- except:
221
- update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ")
222
- update_time = update_time.replace(tzinfo=pytz.utc)
223
- update_time = update_time.astimezone(self.__time_zone)
224
-
225
- this['name'] = i['name']
226
- this['status'] = i['status']
227
- this['wait_time'] = i['waitTime']
228
- this['last_updated'] = update_time
229
- this['entityType'] = "Entertainment"
230
- times[id] = this
231
-
232
- return times
233
-
234
- def get_attraction_wait_times(self):
235
- """Returns a list of dictionaries in the form of {rideid:time} for attractions for this destination"""
236
- data = self.get_themeparkapi_data()
237
-
238
- times = {}
239
-
240
- for i in data:
241
- id = i['id'].split("_")[-1]
242
- try:
243
- if i['meta']['type'] == "ATTRACTION":
244
- times[id] = i['waitTime']
245
- except:
246
- continue
247
-
248
- return times
249
-
250
- def get_attraction_wait_times_detailed(self):
251
- """Returns a list of dictionaries in the form of {rideid:{name, status, wait_time}} for attractions for this destination"""
252
- data = self.get_themeparkapi_data()
253
-
254
- times = {}
255
-
256
- for i in data:
257
- id = i['id'].split("_")[-1]
258
- this = {}
259
- try:
260
- if i['meta']['type'] == "ATTRACTION":
261
-
262
- update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ")
263
- update_time = update_time.replace(tzinfo=pytz.utc)
264
- update_time = update_time.astimezone(self.__time_zone)
265
-
266
- this['name'] = i['name']
267
- this['status'] = i['status']
268
- this['wait_time'] = i['waitTime']
269
- this['last_updated'] = update_time
270
- this['entityType'] = i['meta']['type'].capitalize()
271
- times[id] = this
272
- except:
273
- continue
274
-
275
- return times
276
-
277
- def get_entertainment_wait_times(self):
278
- """Returns a list of dictionaries in the form of {rideid:time} for entertainments for this destination"""
279
- data = self.get_themeparkapi_data()
280
-
281
- times = {}
282
-
283
- for i in data:
284
- id = i['id'].split("_")[-1]
285
- if 'type' not in i['meta'].keys():
286
- times[id] = i['waitTime']
287
-
288
- return times
289
-
290
- def get_entertainment_wait_times_detailed(self):
291
- """Returns a list of dictionaries in the form of {rideid:{name, status, wait_time}} for entertainments for this destination"""
292
- data = self.get_themeparkapi_data()
293
-
294
- times = {}
295
-
296
- for i in data:
297
- id = i['id'].split("_")[-1]
298
- this = {}
299
- if 'type' not in i['meta'].keys():
300
- update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ")
301
- update_time = update_time.replace(tzinfo=pytz.utc)
302
- update_time = update_time.astimezone(self.__time_zone)
303
-
304
- this['name'] = i['name']
305
- this['status'] = i['status']
306
- this['wait_time'] = i['waitTime']
307
- this['last_updated'] = update_time
308
- this['entityType'] = "Entertainment"
309
- times[id] = this
310
-
311
- return times
312
-
313
-
314
- # Deprecated, remove or replace?
315
- # Replace with all park hours
316
- # def get_raw_calendar_data(self, date=""):
317
- # """
318
- # Returns raw calendar data on a date. Date should be in the form yyyy-mm-dd
319
- # """
320
- # if self.__db.channel_exists('{}.calendar.1_0'.format(self.__dest_code)):
321
- # self.__db.sync_calendar_channel()
322
- # else:
323
- # self.__db.create_calendar_channel('{}.calendar.1_0'.format(self.__dest_code))
324
-
325
- # conn = sqlite3.connect(self.__db.db_path)
326
- # c = conn.cursor()
327
- # data = c.execute("SELECT body FROM calendar WHERE date = ?", (date,)).fetchone()
328
- # conn.commit()
329
- # conn.close()
330
-
331
- # if data is None:
332
- # return None
333
- # else:
334
- # return json.loads(data[0])
335
-
336
- # Can only get today's refurbishments now, will probably have to change this
337
- # def get_refurbishments(self, date=""):
338
- # """
339
- # Returns a list of tuples in the form of (id, entityType) that are under refurbishment on a specified date
340
- # date = "YYY-MM-DD"
341
- # """
342
- # if date == "":
343
- # DATE = datetime.today()
344
- # else:
345
- # year, month, day = date.split('-')
346
- # DATE = datetime(int(year), int(month), int(day))
347
-
348
- # STRDATE = "{}-{}-{}".format(DATE.year, self.__formatDate(str(DATE.month)), self.__formatDate(str(DATE.day)))
349
- # date = self.get_raw_calendar_data(STRDATE)
350
-
351
- # ids = []
352
- # try:
353
- # for i in date['refurbishments']:
354
- # split = i['facilityId'].split(";")
355
- # id = split[0]
356
- # entityType = split[1].split("=")[-1]
357
- # ids.append((id, entityType))
358
- # except Exception as e:
359
- # print(e)
360
-
361
- # return ids
362
-
363
- # Similar to refurbishments, can only get today's
364
- # def get_closed(self, date=""):
365
- # """
366
- # Returns a list of tuples in the form of (id, entityType) that are under closed on a specified date
367
- # date = "YYY-MM-DD"
368
- # """
369
- # if date == "":
370
- # DATE = datetime.today()
371
- # else:
372
- # year, month, day = date.split('-')
373
- # DATE = datetime(int(year), int(month), int(day))
374
-
375
- # STRDATE = "{}-{}-{}".format(DATE.year, self.__formatDate(str(DATE.month)), self.__formatDate(str(DATE.day)))
376
- # date = self.get_raw_calendar_data(STRDATE)
377
-
378
- # ids = []
379
- # try:
380
- # for i in date['closed']:
381
- # split = i['facilityId'].split(";")
382
- # id = split[0]
383
- # entityType = split[1].split("=")[-1]
384
- # ids.append((id, entityType))
385
- # except Exception as e:
386
- # print(e)
387
-
388
- # return ids
389
-
390
- def __formatDate(self, num):
391
- """
392
- Formats month and day into proper format
393
- """
394
- if len(num) < 2:
395
- num = '0'+num
396
- return num
397
-
398
- def __str__(self):
399
-
400
- return 'Destination object for {}'.format(self.__name)