Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from scaratozzolo/2.1.0
Browse files Browse the repository at this point in the history
2.1.0
  • Loading branch information
scaratozzolo committed Mar 3, 2021
2 parents 5586eae + 5db41d3 commit d9b4fc0
Show file tree
Hide file tree
Showing 16 changed files with 492 additions and 1,658 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Scott Caratozzolo
Copyright (c) 2021 Scott Caratozzolo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Empty file removed MouseTools/MouseTools.db
Empty file.
3 changes: 1 addition & 2 deletions MouseTools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
from MouseTools.facilities import Facility
from MouseTools.pointsofinterest import PointOfInterest
from MouseTools.destinations import Destination
from MouseTools.database import DisneyDatabase
import MouseTools.ids


name = "MouseTools"

__version__ = "2.0.2"
__version__ = "2.1.0"

__all__ = ["Destination", "Park", "EntertainmentVenue", "Attraction", "Entertainment", "Facility", "Character", "PointOfInterest", "DisneyDatabase"]
151 changes: 53 additions & 98 deletions MouseTools/attractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import sys
import sqlite3
from datetime import datetime, timedelta
from .auth import getHeaders, couchbaseHeaders
from .auth import getHeaders
from .parks import Park
from .database import DisneyDatabase
from .ids import themeparkapi_ids



class Attraction(object):

def __init__(self, id = None, sync_on_init=True):
def __init__(self, id = None):
"""
Constructor Function
Gets all attraction data available and stores various elements into variables.
Expand All @@ -27,26 +28,18 @@ def __init__(self, id = None, sync_on_init=True):
if error:
raise ValueError('That attraction is not available. id: ' + str(id))

self.__db = DisneyDatabase(sync_on_init)
conn = sqlite3.connect(self.__db.db_path)
c = conn.cursor()

self.__id = id
self.__name = self.__data['name']
self.__entityType = self.__data['type']
try:
self.__subType = self.__data['subType']
except:
self.__subType = None
doc_id_query = c.execute("SELECT doc_id from facilities where doc_id LIKE ?", ("%{};entityType={}".format(self.__id, self.__entityType),)).fetchone()
self.__doc_id = doc_id_query[0] if doc_id_query is not None else None
self.__facilities_data = self.get_raw_facilities_data()

try:
self.__anc_dest_id = self.__data['ancestorDestination']['id'].split(';')[0]
self.__dest_code = c.execute("SELECT destination_code FROM facilities WHERE id = ?", (self.__anc_dest_id,)).fetchone()[0]
except:
self.__anc_dest_id = None
self.__dest_code = None

try:
self.__anc_park_id = self.__data['links']['ancestorThemePark']['href'].split('/')[-1].split('?')[0]
Expand Down Expand Up @@ -94,22 +87,6 @@ def __init__(self, id = None, sync_on_init=True):
except:
self.__anc_ev_id = None

conn.commit()
conn.close()

def get_possible_ids(self):
"""Returns a list of possible ids of this entityType"""
attractions = []

dest_data = requests.get("https://api.wdpro.disney.go.com/facility-service/destinations/{}".format(self.__anc_dest_id), headers=getHeaders()).json()
data = requests.get(dest_data['links']['attractions']['href'], headers=getHeaders()).json()

for attract in data['entries']:
try:
attractions.append(attract['links']['self']['href'].split('/')[-1].split('?')[0])
except:
pass
return attractions

def get_id(self):
"""Return object id"""
Expand All @@ -127,14 +104,6 @@ def get_subType(self):
"""Return object subType"""
return self.__subType

def get_doc_id(self):
"""Return object doc id"""
return self.__doc_id

def get_destination_code(self):
"""Return object destination code"""
return self.__dest_code

def get_ancestor_destination_id(self):
"""Return object ancestor destination id"""
return self.__anc_dest_id
Expand Down Expand Up @@ -167,108 +136,77 @@ def get_raw_data(self):
"""Returns the raw data from global-facility-service"""
return self.__data

def get_raw_facilities_data(self):
"""Returns the raw facilities data currently stored in the database"""
conn = sqlite3.connect(self.__db.db_path)
c = conn.cursor()
data = c.execute("SELECT body FROM sync WHERE id = ?", (self.__doc_id,)).fetchone()
conn.commit()
conn.close()

if data is None:
return None
else:
return json.loads(data[0])

def get_raw_facilitystatus_data(self):
"""Returns the raw facilitystatus data from the database after syncing with Disney (returns most recent data)"""
if self.__db.channel_exists('{}.facilitystatus.1_0'.format(self.__dest_code)):
self.__db.sync_facilitystatus_channel()
else:
self.__db.create_facilitystatus_channel('{}.facilitystatus.1_0'.format(self.__dest_code))

conn = sqlite3.connect(self.__db.db_path)
c = conn.cursor()

data = c.execute("SELECT body FROM sync WHERE id = ?", ("{}.facilitystatus.1_0.{};entityType=Attraction".format(self.__dest_code, self.__id),)).fetchone()
if data is None:
return None
else:
return json.loads(data[0])
def get_themeparkapi_data(self):
"""Returns the dictionary from the themepark api for the given id"""
park = themeparkapi_ids[self.__anc_park_id]
themepark_id = f"{park}_{self.__id}"
all_data = requests.get(f"https://api.themeparks.wiki/preview/parks/{park}/waittime").json()
for i in all_data:
if i["id"] == themepark_id:
return i
return None

def get_wait_time(self):
"""Return current wait time of the object. Returns None if object doesn't have a wait time or no wait currently exists (eg. closed)"""
data = self.get_raw_facilitystatus_data()
data = self.get_themeparkapi_data()
if data is None:
return None
else:
return data['waitMinutes']
return data['waitTime']

def get_status(self):
"""Return current status of the object."""
data = self.get_raw_facilitystatus_data()
data = self.get_themeparkapi_data()
if data is None:
return None
else:
return data['status']
# TODO might have to change this from facilitystatus data to scheduleType from today, or test if none from status then get from today instead

def fastpass_available(self):
"""Returns a boolean of whether this object has FastPass"""
data = self.get_raw_facilitystatus_data()
data = self.get_themeparkapi_data()
if data is None:
return False
else:
return data['fastPassAvailable'] == 'true'

def fastpass_times(self):
"""Returns the current start and end time of the FastPass"""
start_time = None
end_time = None

if self.fastpass_available():
data = self.get_raw_facilitystatus_data()

start_time = datetime.strptime(data['fastPassStartTime'], "%Y-%m-%dT%H:%M:%SZ")
end_time = datetime.strptime(data['fastPassEndTime'], "%Y-%m-%dT%H:%M:%SZ")

return start_time, end_time
return data['fastPass']

def get_last_update(self):
"""Returns facilities last update time as a datetime object"""
facility_data = self.get_raw_facilities_data()
facility_data = self.get_themeparkapi_data()
if facility_data is None:
return None
else:
return datetime.strptime(facility_data['lastUpdate'], "%Y-%m-%dT%H:%M:%SZ")
return datetime.strptime(facility_data['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ")

def get_coordinates(self):
"""Returns the object's latitude and longitude"""
facility_data = self.get_raw_facilities_data()
if facility_data is None:
try:
return self.__data['coordinates']['Guest Entrance']['gps']
except:
return None
else:
return facility_data['latitude'], facility_data['longitude']

def get_description(self):
"""Returns the object's descriptions"""
facility_data = self.get_raw_facilities_data()
"""Returns the object's description"""
facility_data = self.__data
if facility_data is None:
return None
else:
return facility_data['description']
try:
return facility_data['descriptions']['shortDescription']['sections']['body']
except:
return None

def get_list_image(self):
"""Returns the url to the object's list image"""
facility_data = self.get_raw_facilities_data()
def get_media(self):
"""Returns a dictionary of dictionaries of media relating to the entity"""
facility_data = self.__data
if facility_data is None:
return None
else:
return facility_data['listImageUrl']
return facility_data['media']

def get_facets(self):
"""Returns a list of dictionaries of the object's facets"""
facility_data = self.get_raw_facilities_data()
facility_data = self.__data
if facility_data is None:
return None
else:
Expand All @@ -277,6 +215,23 @@ def get_facets(self):
except:
return None

def get_classifications(self):
"""Returns a dictionary of lists of classifications related to the entity"""

classifications = {}

try:
for i in self.__data['classifications']:
id = i['id'].split("/")[-1]
if id not in classifications:
classifications[id] = [i['text']]
else:
classifications[id].append(i['text'])
except:
pass

return classifications

def admission_required(self):
"""Returns boolean of admission required"""
return self.__data['admissionRequired']
Expand All @@ -287,7 +242,7 @@ def get_hours(self, date = ""):
Returns the object's hours in the following order: operating open, operating close, Extra Magic open, Extra Magic close.
Extra Magic hours will return None if there are none for today.
If all hours are None then Disney has no hours for that day.
date = "YEAR-MONTH-DATE"
date = "yyyy-mm-dd"
If you don't pass a date, it will get today's hours
"""

Expand Down
5 changes: 0 additions & 5 deletions MouseTools/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,3 @@ def getHeaders():
headers = {"Authorization":"BEARER {}".format(access_token), "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36", "Content-Type":"application/json;charset=UTF-8","Accept":"*/*"}

return headers

def couchbaseHeaders():

header = {"Authorization":"Basic RFBFQ1AtTU9CSUxFLldEVy5BTkRST0lELVBST0Q6RGhyeHMyZHVReGdiVjZ5Mg==","User-Agent":"CouchbaseLite/1.3 (1.4.1/8a21c5927a273a038fb3b66ec29c86425e871b11)","Content-Type":"application/json","Accept":"multipart/related"}
return header
54 changes: 6 additions & 48 deletions MouseTools/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from .attractions import Attraction
from .entertainments import Entertainment
from .facilities import Facility
from .database import DisneyDatabase



class Character(object):

def __init__(self, id = None, sync_on_init=True):
def __init__(self, id = None):
"""
Constructor Function
Gets all character data available and stores various elements into variables.
Expand All @@ -29,26 +29,17 @@ def __init__(self, id = None, sync_on_init=True):
if error:
raise ValueError('That character is not available. id: ' + str(id))

self.__db = DisneyDatabase(sync_on_init)
conn = sqlite3.connect(self.__db.db_path)
c = conn.cursor()

self.__id = id
self.__name = self.__data['name']
self.__entityType = self.__data['type']
try:
self.__subType = self.__data['subType']
except:
self.__subType = None
doc_id_query = c.execute("SELECT doc_id from facilities where doc_id LIKE ?", ("%{};entityType={}".format(self.__id, self.__entityType),)).fetchone()
self.__doc_id = doc_id_query[0] if doc_id_query is not None else None
self.__facilities_data = self.get_raw_facilities_data()
try:
self.__anc_dest_id = self.__data['ancestorDestination']['id'].split(';')[0]
self.__dest_code = c.execute("SELECT destination_code FROM facilities WHERE id = ?", (self.__anc_dest_id,)).fetchone()[0]
except:
self.__anc_dest_id = None
self.__dest_code = None

try:
self.__anc_park_id = self.__data['links']['ancestorThemePark']['href'].split('/')[-1].split('?')[0]
Expand Down Expand Up @@ -96,24 +87,7 @@ def __init__(self, id = None, sync_on_init=True):
except:
self.__anc_ev_id = None

conn.commit()
conn.close()



def get_possible_ids(self):
"""Returns a list of possible ids of this entityType"""
ids = []

data = requests.get("https://api.wdpro.disney.go.com/facility-service/characters", headers=getHeaders()).json()

for entry in data['entries']:
try:
ids.append(entry['links']['self']['href'].split('/')[-1].split('?')[0])
except:
pass

return ids

def get_id(self):
"""Return object id"""
Expand All @@ -131,14 +105,6 @@ def get_subType(self):
"""Return object subType"""
return self.__subType

def get_doc_id(self):
"""Return object doc id"""
return self.__doc_id

def get_destination_code(self):
"""Return object destination code"""
return self.__dest_code

def get_ancestor_destination_id(self):
"""Return object ancestor destination id"""
return self.__anc_dest_id
Expand All @@ -163,22 +129,14 @@ def get_ancestor_entertainment_venue_id(self):
"""Return object entertainment venue id"""
return self.__anc_ev_id

def get_raw_data(self):
"""Returns the raw data from global-facility-service"""
return self.__data

def get_links(self):
"""Returns a dictionary of related links"""
return self.__data['links']

def get_raw_facilities_data(self):
"""Returns the raw facilities data currently stored in the database"""
conn = sqlite3.connect(self.__db.db_path)
c = conn.cursor()
data = c.execute("SELECT body FROM sync WHERE id = ?", (self.__doc_id,)).fetchone()
conn.commit()
conn.close()

if data is None:
return None
else:
return json.loads(data[0])

def check_related_locations(self):
"""
Expand Down
Loading

0 comments on commit d9b4fc0

Please sign in to comment.