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.
@@ -0,0 +1,8 @@
1
+ from mousetools.entities.base import Entity
2
+
3
+
4
+ class Event(Entity):
5
+ """Class for Event Entities."""
6
+
7
+ def __repr__(self) -> str:
8
+ return f"Event(id='{self.id}')"
@@ -0,0 +1,8 @@
1
+ from mousetools.entities.base import Entity
2
+
3
+
4
+ class MerchandiseFacility(Entity):
5
+ """Class for MerchandiseFacility Entities."""
6
+
7
+ def __repr__(self) -> str:
8
+ return f"MerchandiseFacility(id='{self.id}')"
@@ -0,0 +1,8 @@
1
+ from mousetools.entities.base import Entity
2
+
3
+
4
+ class Park(Entity):
5
+ """Class for Park Entities."""
6
+
7
+ def __repr__(self) -> str:
8
+ return f"Park(id='{self.id}')"
@@ -0,0 +1,8 @@
1
+ from mousetools.entities.base import Entity
2
+
3
+
4
+ class Resort(Entity):
5
+ """Class for Resort Entities."""
6
+
7
+ def __repr__(self) -> str:
8
+ return f"Resort(id='{self.id}')"
@@ -0,0 +1,8 @@
1
+ from mousetools.entities.base import Entity
2
+
3
+
4
+ class Restaurant(Entity):
5
+ """Class for Restaurant Entities."""
6
+
7
+ def __repr__(self) -> str:
8
+ return f"Restaurant(id='{self.id}')"
@@ -0,0 +1,17 @@
1
+ class MouseToolsException(Exception):
2
+ """Base class for all MouseTools exceptions."""
3
+
4
+
5
+ class EntityIDNotFound(MouseToolsException):
6
+ """Raised when an enity id could not be found."""
7
+
8
+ # TODO add id to message
9
+ def __init__(self, message="Entity ID not found."):
10
+ super().__init__(message)
11
+
12
+
13
+ class AncestorDestinationMissing(MouseToolsException):
14
+ """Raised for entities missing ancestor destination."""
15
+
16
+ def __init__(self, message="Entity missing ancestor destination id."):
17
+ super().__init__(message)
mousetools/ids.py CHANGED
@@ -1,44 +1,90 @@
1
- from .auth import get_headers
2
- import requests
3
- import json
4
-
5
- WDW_ID = '80007798'
6
- DLR_ID = '80008297'
7
- DESTINATION_IDS = [WDW_ID, DLR_ID]
8
-
9
- MK_ID = "80007944"
10
- EPCOT_ID = "80007838"
11
- HS_ID = "80007998"
12
- AK_ID = "80007823"
13
- DLP_ID = "330339"
14
- CA_ID = "336894"
15
- TL_ID = "80007981"
16
- BB_ID = "80007834"
17
- WDW_PARK_IDS = [MK_ID, EPCOT_ID, HS_ID, AK_ID, TL_ID, BB_ID]
18
- DLR_PARK_IDS = [DLP_ID, CA_ID]
19
-
20
- themeparkapi_ids = {MK_ID: "WaltDisneyWorldMagicKingdom", EPCOT_ID: "WaltDisneyWorldEpcot", HS_ID: "WaltDisneyWorldHollywoodStudios",
21
- AK_ID: "WaltDisneyWorldAnimalKingdom", DLP_ID: "DisneylandResortMagicKingdom", CA_ID: "DisneylandResortCaliforniaAdventure"}
22
-
23
-
24
- def ids(dest, type):
25
- dest_data = requests.get("https://api.wdpro.disney.go.com/facility-service/destinations/{}".format(dest), headers=get_headers()).json()
26
- ids = []
27
-
28
- data = requests.get(dest_data['links'][type]['href'], headers=get_headers()).json()
29
-
30
- for enter in data['entries']:
31
- try:
32
- ids.append(enter['links']['self']['href'].split('/')[-1].split('?')[0])
33
- except:
34
- pass
35
- return ids
36
-
37
- WDW_EV_IDS = ids(WDW_ID, "entertainmentVenues")
38
- DLR_EV_IDS = ids(DLR_ID, "entertainmentVenues")
39
-
40
- WDW_ATTRACTION_IDS = ids(WDW_ID, "attractions")
41
- DLR_ATTRACTION_IDS = ids(DLR_ID, "attractions")
42
-
43
- WDW_ENTERTAINMENT_IDS = ids(WDW_ID, "entertainments")
44
- DLR_ENTERTAINMENT_IDS = ids(DLR_ID, "entertainments")
1
+ from datetime import datetime
2
+ from dataclasses import dataclass
3
+ from concurrent.futures import ThreadPoolExecutor, as_completed
4
+ from mousetools.auth import auth_obj
5
+ from mousetools.urls import ANCESTOR_ENTITIES_BASE_URL
6
+ import requests
7
+ import logging
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ @dataclass(frozen=True)
13
+ class DestinationIds:
14
+ WALT_DISNEY_WORLD: str = "80007798;entityType=destination"
15
+ """The destination id for Walt Disney World."""
16
+ DISNEYLAND_RESORT: str = "80008297;entityType=destination"
17
+ """The destination id for Disneyland Resort."""
18
+
19
+
20
+ @dataclass(frozen=True)
21
+ class WaltDisneyWorldParkIds:
22
+ MAGIC_KINGDOM: str = "80007944;entityType=theme-park"
23
+ """The Park id for Magic Kingdom."""
24
+ EPCOT: str = "80007838;entityType=theme-park"
25
+ """The Park id for Epcot."""
26
+ HOLLYWOOD_STUDIOS: str = "80007998;entityType=theme-park"
27
+ """The Park id for Hollywood Studios."""
28
+ ANIMAL_KINGDOM: str = "80007823;entityType=theme-park"
29
+ """The Park id for Animal Kingdom."""
30
+ TYPHOON_LAGOON: str = "80007981;entityType=water-park"
31
+ """The Park id for Typhoon Lagoon."""
32
+ BLIZZARD_BEACH: str = "80007834;entityType=water-park"
33
+ """The Park id for Blizzard Beach."""
34
+
35
+
36
+ @dataclass(frozen=True)
37
+ class DisneylandResortParkIds:
38
+ DISNEYLAND: str = "330339;entityType=theme-park"
39
+ """The Park id for Disneyland."""
40
+ CALIFORNIA_ADVENTURE: str = "336894;entityType=theme-park"
41
+ """The Park id for California Adventure."""
42
+
43
+
44
+ @dataclass(frozen=True)
45
+ class ThemeParkAPIIds:
46
+ WALT_DISNEY_WORLD: str = "e957da41-3552-4cf6-b636-5babc5cbc4e5"
47
+ """The ThemeParks.Wiki id for Walt Disney World."""
48
+ MAGIC_KINGDOM: str = "75ea578a-adc8-4116-a54d-dccb60765ef9"
49
+ """The ThemeParks.Wiki id for Magic Kingdom."""
50
+ EPCOT: str = "47f90d2c-e191-4239-a466-5892ef59a88b"
51
+ """The ThemeParks.Wiki id for Epcot."""
52
+ HOLLYWOOD_STUDIOS: str = "288747d1-8b4f-4a64-867e-ea7c9b27bad8"
53
+ """The ThemeParks.Wiki id for Hollywood Studios."""
54
+ ANIMAL_KINGDOM: str = "1c84a229-8862-4648-9c71-378ddd2c7693"
55
+ """The ThemeParks.Wiki id for Animal Kingdom."""
56
+ TYPHOON_LAGOON: str = "b070cbc5-feaa-4b87-a8c1-f94cca037a18"
57
+ """The ThemeParks.Wiki id for Typhoon Lagoon."""
58
+ BLIZZARD_BEACH: str = "ead53ea5-22e5-4095-9a83-8c29300d7c63"
59
+ """The ThemeParks.Wiki id for Blizzard Beach."""
60
+
61
+ DISNEYLAND_RESORT: str = "bfc89fd6-314d-44b4-b89e-df1a89cf991e"
62
+ """The ThemeParks.Wiki id for Disneyland Resort."""
63
+ DISNEYLAND: str = "7340550b-c14d-4def-80bb-acdb51d49a6"
64
+ """The ThemeParks.Wiki id for Disneyland."""
65
+ CALIFORNIA_ADVENTURE: str = "832fcd51-ea19-4e77-85c7-75d5843b127c"
66
+ """The ThemeParks.Wiki id for California Adventure."""
67
+
68
+
69
+ def ancestor_entities(dest_id: str):
70
+ if dest_id == DestinationIds.WALT_DISNEY_WORLD:
71
+ destination = "wdw"
72
+ elif dest_id == DestinationIds.DISNEYLAND_RESORT:
73
+ destination = "dlr"
74
+
75
+ results = []
76
+
77
+ today_str = datetime.now().strftime("%Y-%m-%d")
78
+ base_url = f"{ANCESTOR_ENTITIES_BASE_URL}/{destination}/{dest_id}/{today_str}"
79
+ entity_names = ["/entertainment", "/dining", "/shops", "/resorts"]
80
+ with ThreadPoolExecutor(max_workers=5) as executor:
81
+ futures = [executor.submit(requests.get, f"{base_url}{i}", headers=auth_obj.get_headers(), timeout=300) for i in entity_names]
82
+ for future in as_completed(futures):
83
+ try:
84
+ response = future.result()
85
+ response.raise_for_status()
86
+ results += response.json()["results"]
87
+ except Exception as e:
88
+ logger.warning("Error getting ancestor entities: %s", e)
89
+
90
+ return results
File without changes
@@ -0,0 +1,64 @@
1
+ import logging
2
+ import requests
3
+ from mousetools.auth import auth_obj
4
+ from mousetools import WALT_DISNEY_WORLD_ENTITIES, DISNEYLAND_RESORT_ENTITIES
5
+ from mousetools.ids import DestinationIds
6
+ from mousetools.exceptions import EntityIDNotFound
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ class DisneyAPIMixin:
12
+ _ancestor_destination_id = None
13
+ # should be set in subclass
14
+ id = ""
15
+
16
+ def get_disney_data(self):
17
+ """
18
+ Finds the entity in the Disney data and stores it in the
19
+ disney_data attribute. Also stores the ancestor destination id in
20
+ the _ancenstor_destination_id attribute.
21
+
22
+ Returns:
23
+ (dict): The disney data.
24
+
25
+ Raises:
26
+ (EntityIDNotFound): If the entity is not found in the Disney data.
27
+ """
28
+ for i in WALT_DISNEY_WORLD_ENTITIES:
29
+ if self.id == i["id"]:
30
+ self._ancestor_destination_id = DestinationIds.WALT_DISNEY_WORLD
31
+ logger.info("Entity %s found in Walt Disney World", self.id)
32
+ return i
33
+
34
+ for i in DISNEYLAND_RESORT_ENTITIES:
35
+ if self.id == i["id"]:
36
+ self._ancestor_destination_id = DestinationIds.DISNEYLAND_RESORT
37
+ logger.info("Entity %s found in Disneyland Resort", self.id)
38
+ return i
39
+
40
+ raise EntityIDNotFound
41
+
42
+ def get_extended_disney_data(self):
43
+ """
44
+ Gets the extended disney data for this entity from the Disney API.
45
+
46
+ The extended data is the data returned by the simple details API endpoint.
47
+
48
+ Returns:
49
+ (dict): The extended disney data.
50
+
51
+ Raises:
52
+ (requests.exceptions.RequestException): If there is an error getting the data.
53
+ """
54
+
55
+ headers = auth_obj.get_headers()
56
+
57
+ try:
58
+ response = requests.get(self.details_simple_url(), headers=headers)
59
+
60
+ response.raise_for_status()
61
+ return response.json()
62
+
63
+ except Exception as e:
64
+ logger.debug("Error getting extended disney data: %s", e)
@@ -0,0 +1,122 @@
1
+ import typing
2
+ import logging
3
+ import requests
4
+ from mousetools.ids import DestinationIds, ThemeParkAPIIds
5
+ from mousetools.urls import THEMEPARK_BASE_URL
6
+ from mousetools.exceptions import AncestorDestinationMissing, EntityIDNotFound
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ class ThemeParkAPIMixin:
12
+ _tp_entity_id = None
13
+ # Should be set in subclass
14
+ id = ""
15
+ ancestor_destination_id: typing.Optional[str] = None
16
+
17
+ @staticmethod
18
+ def _send_tp_request(url: str) -> dict:
19
+ """
20
+ Send a GET request to ThemeParks.Wiki
21
+
22
+ Args:
23
+ url (str): The url to send the request to
24
+
25
+ Returns:
26
+ (dict): The response, parsed as JSON
27
+
28
+ Raises:
29
+ (requests.exceptions.RequestException): If the request fails
30
+ """
31
+ logger.debug("Sending request to %s", url)
32
+ response = requests.get(url)
33
+ response.raise_for_status()
34
+ return response.json()
35
+
36
+ @property
37
+ def tp_entity_id(self) -> str:
38
+ """
39
+ The id of this entity on the ThemeParks.Wiki API.
40
+
41
+ Returns:
42
+ (str): The id of this entity on the ThemeParks.Wiki API
43
+
44
+ Raises:
45
+ (AncestorDestinationMissing): If the ancestor destination id is not
46
+ either Walt Disney World or Disneyland Resort
47
+ (EntityIDNotFound): If no ThemeParks.Wiki API id is found for this entity
48
+ """
49
+
50
+ if self._tp_entity_id is not None:
51
+ return self._tp_entity_id
52
+
53
+ if self.ancestor_destination_id == DestinationIds.WALT_DISNEY_WORLD:
54
+ tp_destination_id = ThemeParkAPIIds.WALT_DISNEY_WORLD
55
+ elif self.ancestor_destination_id == DestinationIds.DISNEYLAND_RESORT:
56
+ tp_destination_id = ThemeParkAPIIds.DISNEYLAND_RESORT
57
+ else:
58
+ raise AncestorDestinationMissing
59
+
60
+ request_url = f"{THEMEPARK_BASE_URL}/entity/{tp_destination_id}/children"
61
+ children = self._send_tp_request(request_url)["children"]
62
+
63
+ for i in children:
64
+ if i["externalId"] == self.id:
65
+ self._tp_entity_id = i["id"]
66
+ return i["id"]
67
+
68
+ raise EntityIDNotFound
69
+
70
+ def get_entity_tp(self) -> dict:
71
+ """
72
+ Get an entity details from the ThemeParks.Wiki API.
73
+
74
+ Returns:
75
+ (dict): The response, parsed as JSON
76
+ """
77
+ request_url = f"{THEMEPARK_BASE_URL}/entity/{self.tp_entity_id}"
78
+ return self._send_tp_request(request_url)
79
+
80
+ def get_entity_children_tp(self) -> dict:
81
+ """
82
+ Get the children entities of an entity from the ThemeParks.Wiki API.
83
+
84
+ Returns:
85
+ (dict): The response, parsed as JSON
86
+ """
87
+ request_url = f"{THEMEPARK_BASE_URL}/entity/{self.tp_entity_id}/children"
88
+ return self._send_tp_request(request_url)
89
+
90
+ def get_entity_live_tp(self) -> dict:
91
+ """
92
+ Get the live data for an entity from the ThemeParks.Wiki API.
93
+
94
+ Returns:
95
+ (dict): The response, parsed as JSON
96
+ """
97
+ request_url = f"{THEMEPARK_BASE_URL}/entity/{self.tp_entity_id}/live"
98
+ return self._send_tp_request(request_url)
99
+
100
+ def get_entity_schedule_tp(
101
+ self,
102
+ year: typing.Optional[typing.Union[int, str]] = None,
103
+ month: typing.Optional[typing.Union[int, str]] = None,
104
+ ) -> dict:
105
+ """
106
+ Get the schedule for an entity from the ThemeParks.Wiki API.
107
+
108
+ Args:
109
+ year (Optional[Union[int, str]], optional): The year for which to get the schedule. Defaults to None.
110
+ month (Optional[Union[int, str]], optional): The month for which to get the schedule. Defaults to None.
111
+
112
+ Returns:
113
+ (dict): The response, parsed as JSON
114
+ """
115
+ request_url = f"{THEMEPARK_BASE_URL}/entity/{self.tp_entity_id}/schedule"
116
+ if year is not None and month is not None:
117
+ request_url = f"{request_url}/{year}/{month}"
118
+ else:
119
+ raise UserWarning(
120
+ "Missing year or month. Both must be passed to be used in request."
121
+ )
122
+ return self._send_tp_request(request_url)
mousetools/urls.py ADDED
@@ -0,0 +1,5 @@
1
+ ANCESTOR_ENTITIES_BASE_URL = "https://disneyworld.disney.go.com/finder/api/v1/explorer-service/list-ancestor-entities"
2
+
3
+ ENTITY_DETAILS_SIMPLE_BASE_URL = "https://disneyworld.disney.go.com/finder/api/v1/explorer-service/details-entity-simple"
4
+
5
+ THEMEPARK_BASE_URL: str = "https://api.themeparks.wiki/v1"
@@ -1,101 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: MouseTools
3
- Version: 2.1.2.dev2
4
- Summary: A Python wrapper for the Disney API
5
- Author: Scott Caratozzolo
6
- Project-URL: repository, https://gitlab.com/caratozzoloxyz/public/MouseTools
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Requires-Dist: requests
13
- Requires-Dist: pytz
14
-
15
- # MouseTools
16
- [![PyPI version](https://badge.fury.io/py/MouseTools.svg)](https://badge.fury.io/py/MouseTools) [![Downloads](https://pepy.tech/badge/mousetools)](https://pepy.tech/project/mousetools)
17
-
18
-
19
- A Python wrapper for the Disney API. Data is pulled directly from Disney. This package supports Walt Disney World and Disneyland.
20
-
21
-
22
- ### Installation
23
- You can install using pip:
24
- ```bash
25
- pip install MouseTools
26
- ```
27
- You can also install directly from this repo in case of any changes not uploaded to Pypi.
28
- ```bash
29
- pip install git+https://github.com/scaratozzolo/MouseTools
30
- ```
31
-
32
-
33
- ### Example usage:
34
- ```python
35
- import mousetools
36
-
37
- wdw_dest = mousetools.Destination(80007798)
38
- print(wdw_dest.get_park_ids())
39
-
40
- dlr_dest = mousetools.Destination(80008297)
41
- print(dlr_dest.get_attraction_ids())
42
-
43
- mk = mousetools.Park(80007944)
44
- print(mk.get_wait_times())
45
-
46
- pirates = mousetools.Attraction(80010177)
47
- print(pirates.get_wait_time())
48
-
49
-
50
- # You don't have to know any ids to get started.
51
- mousetools.ids.WDW_ID # Walt Disney World Resort
52
- mousetools.ids.DLR_ID # Disneyland Resort
53
-
54
- # Single park ids
55
- mousetools.ids.MK_ID # Magic Kingdom
56
- mousetools.ids.EPCOT_ID # EPCOT
57
- mousetools.ids.HS_ID # Hollywood Studios
58
- mousetools.ids.AK_ID # Animal Kingdom
59
- mousetools.ids.TL_ID # Typhoon Lagoon
60
- mousetools.ids.BB_ID # Blizzard Beach
61
- mousetools.ids.DLP_ID # Disneyland Park
62
- mousetools.ids.CA_ID # California Adventure
63
-
64
- # List of ids
65
- # Parks
66
- mousetools.ids.WDW_PARK_IDS
67
- mousetools.ids.DLR_PARK_IDS
68
-
69
- # Entertainment Venues
70
- mousetools.ids.WDW_EV_IDS
71
- mousetools.ids.DLR_EV_IDS
72
-
73
- # Attractions
74
- mousetools.ids.WDW_ATTRACTION_IDS
75
- mousetools.ids.DLR_ATTRACTION_IDS
76
-
77
- # Entertainments
78
- mousetools.ids.WDW_ENTERTAINMENT_IDS
79
- mousetools.ids.DLR_ENTERTAINMENT_IDS
80
-
81
- ```
82
-
83
- For more documentation go to the [wiki](https://github.com/scaratozzolo/MouseTools/wiki) or run the following command from a termainal:
84
- ```Bash
85
- python -m pydoc mousetools
86
- ```
87
-
88
-
89
- I created this project to help with another project found [here](https://github.com/scaratozzolo/WDWWaits). Some parts of the wrapper were created with that in mind.
90
-
91
- If you notice any issues please open a new issue with a "bug" label. Furthermore, if you have any feature requests, open a new issue with a "feature request" label.
92
-
93
- This package uses the [ThemeParks.wiki API](https://api.themeparks.wiki/).
94
-
95
- ### License
96
- This project is distributed under the MIT license. For more information see [LICENSE](https://github.com/scaratozzolo/MouseTools/blob/master/LICENSE)
97
-
98
- https://github.com/scaratozzolo/MouseTools
99
-
100
- ### Disclaimer
101
- This project is in no way affiliated with The Walt Disney Company and all use of Disney Services is subject to the [Disney Terms of Use](https://disneytermsofuse.com/).
@@ -1,16 +0,0 @@
1
- mousetools/__init__.py,sha256=MITXDbBq7NpoeEBC8HrER6RWyvNlAq--662cisomv1k,680
2
- mousetools/attractions.py,sha256=C4RrRdv_pzSfdVm-qktMGgUk8UiYazjw9RIlygk2vhk,13435
3
- mousetools/auth.py,sha256=WtdVhAWP-ushDQOjcqxOZWYdufiFwMTH3FMkXxMiJwI,1532
4
- mousetools/characters.py,sha256=k4JYosNLCzjpF0cCB8akKM8Xl8zHuOCfZSKThKi_lao,8101
5
- mousetools/destinations.py,sha256=CvEuS0dBiNOcguuv-MAcrE8cuQXM3jEnqnlmLDNdACE,13130
6
- mousetools/entertainments.py,sha256=R-cV0dcEplbM6cZyPAAI6-tfrJOaX_bS93pJe2DN2BM,16041
7
- mousetools/entertainmentvenues.py,sha256=EQ-9gtfez1UgdcLcVO524EKimE0O7s9sF7rVD4APh4s,10001
8
- mousetools/facilities.py,sha256=Tzcv_6xFtGzLKVs9qrnSgH45DoDzg9k6mA-l_MMFAF4,9502
9
- mousetools/ids.py,sha256=opSGD1Kerdxtn99oDtVXDli6dqptzqKk2Sz9rVU-uu0,1407
10
- mousetools/parks.py,sha256=wVIlNuI9ehGKSlOKx-ZkMf2egcj3pyfE2Uysrnym_mA,16596
11
- mousetools/pointsofinterest.py,sha256=t1srDGcG_wduvvf_xhkFw6jbbxWh7hhufV-NKrpMLbc,5934
12
- MouseTools-2.1.2.dev2.dist-info/LICENSE,sha256=p6UXQpWnm-JPYIXK741EYHHVnLFUpxPJt1zFcZ4XgfM,1074
13
- MouseTools-2.1.2.dev2.dist-info/METADATA,sha256=Mypc1YdjgsuuqQ435-nZxy0StN8k7Etvu0t4F07Ny8U,3199
14
- MouseTools-2.1.2.dev2.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
15
- MouseTools-2.1.2.dev2.dist-info/top_level.txt,sha256=7nanLN103J_xJn6HK6yuyqqlDgltCsQY2-ArRXx1Ukk,11
16
- MouseTools-2.1.2.dev2.dist-info/RECORD,,