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,470 +0,0 @@
1
- import requests
2
- import json
3
- from datetime import datetime, timedelta
4
- import pytz
5
- from .auth import get_headers
6
- from .parks import Park
7
- from .pointsofinterest import PointOfInterest
8
- from .ids import themeparkapi_ids, WDW_ID, DLR_ID
9
-
10
-
11
-
12
- class Entertainment(object):
13
-
14
- def __init__(self, id = None):
15
- """
16
- Constructor Function
17
- Gets all entertainment data available and stores various elements into variables.
18
- """
19
-
20
- error = True
21
- self.__data = requests.get("https://api.wdpro.disney.go.com/global-pool-override-B/facility-service/entertainments/{}".format(id), headers=get_headers()).json()
22
- try:
23
- if self.__data['id'] is not None:
24
- error = False
25
- except:
26
- pass
27
-
28
- if error:
29
- raise ValueError('That entertainment is not available. id: ' + str(id))
30
-
31
- self.__id = id
32
- self.__name = self.__data['name']
33
- self.__entityType = self.__data['type']
34
- try:
35
- self.__subType = self.__data['subType']
36
- except:
37
- self.__subType = None
38
- try:
39
- self.__anc_dest_id = self.__data['ancestorDestination']['id'].split(';')[0]
40
- except:
41
- self.__anc_dest_id = None
42
-
43
-
44
- try:
45
- self.__anc_park_id = self.__data['links']['ancestorThemePark']['href'].split('/')[-1].split('?')[0]
46
- except:
47
- try:
48
- self.__anc_park_id = self.__data['links']['ancestorWaterPark']['href'].split('/')[-1].split('?')[0]
49
- except:
50
- try:
51
- self.__anc_park_id = self.__data['ancestorThemeParkId'].split(';')[0]
52
- except:
53
- try:
54
- self.__anc_park_id = self.__data['ancestorWaterParkId'].split(';')[0]
55
- except:
56
- self.__anc_park_id = None
57
-
58
- try:
59
- self.__anc_resort_id = self.__data['links']['ancestorResort']['href'].split('/')[-1].split('?')[0]
60
- except:
61
- try:
62
- self.__anc_resort_id = self.__data['ancestorResortId'].split(';')[0]
63
- except:
64
- self.__anc_resort_id = None
65
-
66
- try:
67
- self.__anc_land_id = self.__data['links']['ancestorLand']['href'].split('/')[-1].split('?')[0]
68
- except:
69
- try:
70
- self.__anc_land_id = self.__data['ancestorLandId'].split(';')[0]
71
- except:
72
- self.__anc_land_id = None
73
-
74
- try:
75
- self.__anc_ra_id = self.__data['links']['ancestorResortArea']['href'].split('/')[-1].split('?')[0]
76
- except:
77
- try:
78
- self.__anc_ra_id = self.__data['ancestorResortAreaId'].split(';')[0]
79
- except:
80
- self.__anc_ra_id = None
81
-
82
- try:
83
- self.__anc_ev_id = self.__data['links']['ancestorEntertainmentVenue']['href'].split('/')[-1].split('?')[0]
84
- except:
85
- try:
86
- self.__anc_ev_id = self.__data['ancestorEntertainmentVenueId'].split(';')[0]
87
- except:
88
- self.__anc_ev_id = None
89
-
90
-
91
- if self.__anc_dest_id == WDW_ID:
92
- self.__time_zone = pytz.timezone('US/Eastern')
93
- elif self.__anc_dest_id == DLR_ID:
94
- self.__time_zone = pytz.timezone('US/Pacific')
95
- else:
96
- self.__time_zone = pytz.utc
97
-
98
-
99
-
100
- def get_possible_ids(self):
101
- """Returns a list of possible ids of this entityType"""
102
- entertainments = []
103
-
104
- dest_data = requests.get("https://api.wdpro.disney.go.com/facility-service/destinations/{}".format(self.__anc_dest_id), headers=get_headers()).json()
105
- data = requests.get(dest_data['links']['entertainments']['href'], headers=get_headers()).json()
106
-
107
- for enter in data['entries']:
108
- try:
109
- entertainments.append(enter['links']['self']['href'].split('/')[-1].split('?')[0])
110
- except:
111
- pass
112
-
113
- return entertainments
114
-
115
- def get_id(self):
116
- """Return object id"""
117
- return self.__id
118
-
119
- def get_name(self):
120
- """Return object name"""
121
- return self.__name
122
-
123
- def get_entityType(self):
124
- """Return object entityType"""
125
- return self.__entityType
126
-
127
- def get_subType(self):
128
- """Return object subType"""
129
- return self.__subType
130
-
131
- def get_ancestor_destination_id(self):
132
- """Return object ancestor theme or water park id"""
133
- return self.__anc_dest_id
134
-
135
- def get_ancestor_park_id(self):
136
- """Return object ancestor theme or water park id"""
137
- return self.__anc_park_id
138
-
139
- def get_ancestor_resort_id(self):
140
- """Return object ancestor resort id"""
141
- return self.__anc_resort_id
142
-
143
- def get_ancestor_land_id(self):
144
- """Return object land id"""
145
- return self.__anc_land_id
146
-
147
- def get_ancestor_resort_area_id(self):
148
- """Return object resort area id"""
149
- return self.__anc_ra_id
150
-
151
- def get_ancestor_entertainment_venue_id(self):
152
- """Return object entertainment venue id"""
153
- return self.__anc_ev_id
154
-
155
- def get_links(self):
156
- """Returns a dictionary of related links"""
157
- return self.__data['links']
158
-
159
- def get_time_zone(self):
160
- """Returns pytz timezone object"""
161
- return self.__time_zone
162
-
163
- def get_raw_data(self):
164
- """Returns the raw data from global-facility-service"""
165
- return self.__data
166
-
167
- def get_themeparkapi_data(self):
168
- """Returns the dictionary from the themepark api for the given id"""
169
- park = themeparkapi_ids[self.__anc_park_id]
170
- themepark_id = f"{park}_{self.__id}"
171
- all_data = requests.get(f"https://api.themeparks.wiki/preview/parks/{park}/waittime").json()
172
- for i in all_data:
173
- if i["id"] == themepark_id:
174
- return i
175
- return None
176
-
177
- def get_wait_time(self):
178
- """Return current wait time of the object. Returns None if object doesn't have a wait time or no wait currently exists (eg. closed)"""
179
- data = self.get_themeparkapi_data()
180
- if data is None:
181
- return None
182
- else:
183
- return data['waitTime']
184
-
185
- def get_status(self):
186
- """Return current status of the object."""
187
- data = self.get_themeparkapi_data()
188
- if data is None:
189
- return None
190
- else:
191
- return data['status']
192
-
193
- def fastpass_available(self):
194
- """Returns a boolean of whether this object has FastPass"""
195
- data = self.get_themeparkapi_data()
196
- if data is None:
197
- return False
198
- else:
199
- return data['fastPass']
200
-
201
- def get_last_update_time(self):
202
- """Returns facilities last update time as a datetime object"""
203
- facility_data = self.get_themeparkapi_data()
204
- if facility_data is None:
205
- return None
206
- else:
207
- update_time = datetime.strptime(facility_data['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ")
208
- update_time = update_time.replace(tzinfo=pytz.utc)
209
- update_time = update_time.astimezone(self.__time_zone)
210
- return update_time
211
-
212
- def get_coordinates(self):
213
- """Returns the object's latitude and longitude"""
214
- try:
215
- return self.__data['coordinates']['Guest Entrance']['gps']
216
- except:
217
- return None
218
-
219
- def get_description(self):
220
- """Returns the object's description"""
221
- facility_data = self.__data
222
- if facility_data is None:
223
- return None
224
- else:
225
- try:
226
- return facility_data['descriptions']['shortDescription']['sections']['body']
227
- except:
228
- return None
229
-
230
- def get_media(self):
231
- """Returns a dictionary of dictionaries of media relating to the entity"""
232
- facility_data = self.__data
233
- if facility_data is None:
234
- return None
235
- else:
236
- return facility_data['media']
237
-
238
- def get_facets(self):
239
- """Returns a list of dictionaries of the object's facets"""
240
- facility_data = self.get_themeparkapi_data()
241
- if facility_data is None:
242
- return None
243
- else:
244
- try:
245
- return facility_data['facets']
246
- except:
247
- return None
248
-
249
- def get_classifications(self):
250
- """Returns a dictionary of lists of classifications related to the entity"""
251
-
252
- classifications = {}
253
-
254
- try:
255
- for i in self.__data['classifications']:
256
- id = i['id'].split("/")[-1]
257
- if id not in classifications:
258
- classifications[id] = [i['text']]
259
- else:
260
- classifications[id].append(i['text'])
261
- except:
262
- pass
263
-
264
- return classifications
265
-
266
- def admission_required(self):
267
- """Returns boolean of admission required"""
268
- return self.__data['admissionRequired']
269
-
270
- def check_associated_characters(self):
271
- """
272
- Checks if object has any associated characters
273
- """
274
- s = requests.get("https://api.wdpro.disney.go.com/global-pool-override-B/facility-service/associated-characters/{};entityType={}".format(self.__id, self.__entityType), headers=get_headers())
275
- data = json.loads(s.content)
276
-
277
- if data['total'] > 0:
278
- return True
279
- else:
280
- return False
281
-
282
- def get_number_associated_characters(self):
283
- """
284
- Gets the total number of characters associated with this object
285
- """
286
- s = requests.get("https://api.wdpro.disney.go.com/global-pool-override-B/facility-service/associated-characters/{};entityType={}".format(self.__id, self.__entityType), headers=get_headers())
287
- data = json.loads(s.content)
288
-
289
- return data['total']
290
-
291
- def get_associated_characters(self):
292
- """
293
- Returns a list of associated characters Character objects
294
- """
295
- from .characters import Character
296
- chars = []
297
-
298
- s = requests.get("https://api.wdpro.disney.go.com/global-pool-override-B/facility-service/associated-characters/{};entityType={}".format(self.__id, self.__entityType), headers=get_headers())
299
- data = json.loads(s.content)
300
-
301
- for i in range(len(data['entries'])):
302
- try:
303
- chars.append(Character(data['entries'][i]['links']['self']['href'].split('/')[-1]))
304
- except:
305
- pass
306
-
307
- return chars
308
-
309
- def get_associated_character_ids(self):
310
- """
311
- Returns a list of associated characters IDs
312
- """
313
- chars = []
314
-
315
- s = requests.get("https://api.wdpro.disney.go.com/global-pool-override-B/facility-service/associated-characters/{};entityType={}".format(self.__id, self.__entityType), headers=get_headers())
316
- data = json.loads(s.content)
317
-
318
- for i in range(len(data['entries'])):
319
- try:
320
- chars.append(data['entries'][i]['links']['self']['href'].split('/')[-1])
321
- except:
322
- pass
323
-
324
- return chars
325
-
326
- def check_related_locations(self):
327
- """
328
- Returns true if it has related locations, false if none
329
- """
330
- try:
331
- check = self.__data['relatedLocations']
332
- return True
333
- except:
334
- return False
335
-
336
- def get_related_locations(self):
337
- """
338
- Returns the related locations of the entertainment
339
- """
340
- locs = []
341
- try:
342
- if self.check_related_locations():
343
- for loc in self.__data['relatedLocations']['primaryLocations']:
344
- type = loc['facilityType']
345
- loc_id = loc['links']['self']['href'].split('/')[-1].split('?')[0]
346
-
347
- if type == 'point-of-interest':
348
- locs.append(PointOfInterest(loc_id))
349
- else:
350
- print('no class for {} at this time'.format(type))
351
- return locs
352
- except:
353
- return locs
354
-
355
- def get_related_location_ids(self):
356
- """
357
- Returns the related locations of the entertainment as a tuple (id, type)
358
- """
359
- locs = []
360
- try:
361
- if self.check_related_locations():
362
- for loc in self.__data['relatedLocations']['primaryLocations']:
363
- type = loc['facilityType']
364
- loc_id = loc['links']['self']['href'].split('/')[-1].split('?')[0]
365
-
366
- locs.append((loc_id, type))
367
-
368
- return locs
369
- except:
370
- return locs
371
-
372
-
373
- def get_start_date(self):
374
- """
375
- Gets the start date of the entertainment and returns it as a datetime object. If there is no start date, returns None
376
- """
377
- date = self.__data['startDate']
378
- if date == "":
379
- return None
380
-
381
- date = date.split('-')
382
- return datetime(int(date[0]), int(date[1]), int(date[2]))
383
-
384
- def get_end_date(self):
385
- """
386
- Gets the start date of the entertainment and returns it as a datetime object. If there is no start date, returns None.
387
- """
388
- date = self.__data['endDate']
389
- if date == "":
390
- return None
391
-
392
- date = date.split('-')
393
- return datetime(int(date[0]), int(date[1]), int(date[2]))
394
-
395
- def get_duration(self):
396
- """
397
- Returns the string format of the duration of the entertainment as provided by Disney
398
- """
399
- return self.__data['duration']
400
-
401
- def get_duration_minutes(self):
402
- """
403
- Returns the duration of the entertainment in minutes as a float
404
- """
405
- dur = self.__data['duration'].split(':')
406
- return float(int(dur[0])*60 + int(dur[1]) + int(dur[2])/60)
407
-
408
- def get_duration_seconds(self):
409
- """
410
- Returns the duration of the entertainment in seconds as an integer
411
- """
412
- dur = self.__data['duration'].split(':')
413
- return int(self.get_duration_minutes())*60 + int(dur[2])
414
-
415
- def get_schedule(self, date="", timestamp=False):
416
- """
417
- Returns a list of dictionaries for the specified date's schedule in the form of [{start_time, end_time}]
418
- date = "YYYY-MM-DD"
419
- If you don't pass a date, it will get today's schedule
420
- timestamp = False
421
- Whether to return datetime objects or timestamps
422
- """
423
-
424
- if date == "":
425
- DATE = datetime.today()
426
- else:
427
- year, month, day = date.split('-')
428
- DATE = datetime(int(year), int(month), int(day))
429
-
430
- strdate = "{}-{}-{}".format(DATE.year, self.__formatDate(str(DATE.month)), self.__formatDate(str(DATE.day)))
431
- data = requests.get("https://api.wdpro.disney.go.com/facility-service/schedules/{}?date={}".format(self.__id, strdate), headers=get_headers()).json()
432
-
433
- schedule = []
434
-
435
- try:
436
- for entry in data['schedules']:
437
- if entry['type'] == 'Performance Time':
438
- this = {}
439
- start_time = datetime.strptime("{} {}".format(entry['date'], entry['startTime']), "%Y-%m-%d %H:%M:%S")
440
- end_time = datetime.strptime("{} {}".format(entry['date'], entry['endTime']), "%Y-%m-%d %H:%M:%S")
441
- if timestamp:
442
- this['start_time'] = start_time.timestamp()
443
- this['end_time'] = end_time.timestamp()
444
- else:
445
- this['start_time'] = start_time
446
- this['end_time'] = end_time
447
- schedule.append(this)
448
- except Exception as e:
449
- # print(e)
450
- pass
451
-
452
- return schedule
453
-
454
-
455
- def __formatDate(self, num):
456
- """
457
- Formats month and day into proper format
458
- """
459
- if len(num) < 2:
460
- num = '0'+num
461
- return num
462
-
463
- def __eq__(self, other):
464
- """
465
- Checks if objects are equal
466
- """
467
- return self.__id == other.get_id()
468
-
469
- def __str__(self):
470
- return 'Entertainment object for {}'.format(self.__name)