diff --git a/MouseTools/attractions.py b/MouseTools/attractions.py index d58f93f..0c8f95c 100644 --- a/MouseTools/attractions.py +++ b/MouseTools/attractions.py @@ -1,11 +1,10 @@ import requests import json -import sys -import sqlite3 from datetime import datetime, timedelta +import pytz from .auth import get_headers from .parks import Park -from .ids import themeparkapi_ids +from .ids import themeparkapi_ids, WDW_ID, DLR_ID @@ -87,6 +86,13 @@ def __init__(self, id = None): except: self.__anc_ev_id = None + if self.__anc_dest_id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__anc_dest_id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') + def get_id(self): """Return object id""" @@ -132,6 +138,10 @@ def get_links(self): """Returns a dictionary of related links""" return self.__data['links'] + def get_time_zone(self): + """Returns pytz timezone object""" + return self.__time_zone + def get_raw_data(self): """Returns the raw data from global-facility-service""" return self.__data @@ -170,14 +180,16 @@ def fastpass_available(self): else: return data['fastPass'] - def get_last_update(self): + def get_last_update_time(self): """Returns facilities last update time as a datetime object""" facility_data = self.get_themeparkapi_data() if facility_data is None: return None else: - print(facility_data['lastUpdate']) - return datetime.strptime(facility_data['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = datetime.strptime(facility_data['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + return update_time def get_coordinates(self): """Returns the object's latitude and longitude""" diff --git a/MouseTools/characters.py b/MouseTools/characters.py index 927629d..86be1b3 100644 --- a/MouseTools/characters.py +++ b/MouseTools/characters.py @@ -1,12 +1,11 @@ import requests -import json -import sys -import sqlite3 +import pytz from datetime import datetime, timedelta from .auth import get_headers from .attractions import Attraction from .entertainments import Entertainment from .facilities import Facility +from .ids import WDW_ID, DLR_ID @@ -87,6 +86,12 @@ def __init__(self, id = None): except: self.__anc_ev_id = None + if self.__anc_dest_id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__anc_dest_id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') def get_id(self): @@ -129,6 +134,10 @@ def get_ancestor_entertainment_venue_id(self): """Return object entertainment venue id""" return self.__anc_ev_id + def get_time_zone(self): + """Returns pytz timezone object""" + return self.__time_zone + def get_raw_data(self): """Returns the raw data from global-facility-service""" return self.__data diff --git a/MouseTools/destinations.py b/MouseTools/destinations.py index 409c34e..290caf1 100644 --- a/MouseTools/destinations.py +++ b/MouseTools/destinations.py @@ -1,8 +1,6 @@ import requests -import json -import sys -import sqlite3 from datetime import datetime, timedelta +import pytz from .auth import get_headers from .parks import Park from .entertainments import Entertainment @@ -32,6 +30,13 @@ def __init__(self, id = None): self.__name = self.__data['name'] self.__entityType = self.__data['type'] + if self.__id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') + @@ -55,6 +60,10 @@ def get_links(self): """Returns a dictionary of related links""" return self.__data['links'] + def get_time_zone(self): + """Returns pytz timezone object""" + return self.__time_zone + def get_raw_data(self): """Returns the raw data from global-facility-service""" return self.__data @@ -197,17 +206,26 @@ def get_wait_times_detailed(self): this = {} try: if i['meta']['type'] != "RESTAURANT": + + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = i['meta']['type'].capitalize() times[id] = this except: + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = "Entertainment" times[id] = this @@ -240,10 +258,15 @@ def get_attraction_wait_times_detailed(self): this = {} try: if i['meta']['type'] == "ATTRACTION": + + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = i['meta']['type'].capitalize() times[id] = this except: @@ -274,10 +297,14 @@ def get_entertainment_wait_times_detailed(self): id = i['id'].split("_")[-1] this = {} if 'type' not in i['meta'].keys(): + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = "Entertainment" times[id] = this diff --git a/MouseTools/entertainments.py b/MouseTools/entertainments.py index cf55037..6446b3e 100644 --- a/MouseTools/entertainments.py +++ b/MouseTools/entertainments.py @@ -1,12 +1,11 @@ import requests import json -import sys -import sqlite3 from datetime import datetime, timedelta +import pytz from .auth import get_headers from .parks import Park from .pointsofinterest import PointOfInterest -from .ids import themeparkapi_ids +from .ids import themeparkapi_ids, WDW_ID, DLR_ID @@ -87,6 +86,14 @@ def __init__(self, id = None): self.__anc_ev_id = self.__facilities_data['ancestorEntertainmentVenueId'].split(';')[0] except: self.__anc_ev_id = None + + + if self.__anc_dest_id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__anc_dest_id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') @@ -149,6 +156,10 @@ def get_links(self): """Returns a dictionary of related links""" return self.__data['links'] + def get_time_zone(self): + """Returns pytz timezone object""" + return self.__time_zone + def get_raw_data(self): """Returns the raw data from global-facility-service""" return self.__data @@ -187,13 +198,16 @@ def fastpass_available(self): else: return data['fastPass'] - def get_last_update(self): + def get_last_update_time(self): """Returns facilities last update time as a datetime object""" 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:%S.%fZ") + update_time = datetime.strptime(facility_data['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + return update_time def get_coordinates(self): """Returns the object's latitude and longitude""" diff --git a/MouseTools/entertainmentvenues.py b/MouseTools/entertainmentvenues.py index 429c333..735540d 100644 --- a/MouseTools/entertainmentvenues.py +++ b/MouseTools/entertainmentvenues.py @@ -1,10 +1,9 @@ import requests import json -import sys -import sqlite3 +import pytz from datetime import datetime, timedelta from .auth import get_headers - +from .ids import WDW_ID, DLR_ID class EntertainmentVenue(object): @@ -84,6 +83,13 @@ def __init__(self, id = None): except: self.__anc_ev_id = None + if self.__anc_dest_id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__anc_dest_id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') + def get_possible_ids(self): """Returns a list of possible ids of this entityType""" @@ -144,6 +150,10 @@ def get_links(self): """Returns a dictionary of related links""" return self.__data['links'] + def get_time_zone(self): + """Returns pytz timezone object""" + return self.__time_zone + def get_raw_data(self): """Returns the raw data from global-facility-service""" return self.__data diff --git a/MouseTools/facilities.py b/MouseTools/facilities.py index 5d26781..98b219c 100644 --- a/MouseTools/facilities.py +++ b/MouseTools/facilities.py @@ -1,10 +1,9 @@ import requests import json -import sys -import sqlite3 +import pytz from datetime import datetime, timedelta from .auth import get_headers - +from .ids import WDW_ID, DLR_ID class Facility(object): @@ -85,6 +84,13 @@ def __init__(self, id = None): except: self.__anc_ev_id = None + if self.__anc_dest_id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__anc_dest_id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') + # There are just too many variations, could explore more # def get_possible_ids(self): # """Returns a list of possible ids of this entityType""" diff --git a/MouseTools/parks.py b/MouseTools/parks.py index 46728f3..a80fddb 100644 --- a/MouseTools/parks.py +++ b/MouseTools/parks.py @@ -1,10 +1,9 @@ import requests import json -import sys -import sqlite3 +import pytz from datetime import datetime, timedelta from .auth import get_headers -from .ids import themeparkapi_ids +from .ids import themeparkapi_ids, WDW_ID, DLR_ID class Park(object): @@ -92,6 +91,14 @@ def __init__(self, id = None): except: self.__anc_ev_id = None + + if self.__id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') + def get_possible_ids(self): """Returns a list of possible ids of this entityType""" @@ -162,6 +169,10 @@ def get_links(self): """Returns a dictionary of related links""" return self.__data['links'] + def get_time_zone(self): + """Returns pytz timezone object""" + return self.__time_zone + def get_raw_data(self): """Returns the raw data from global-facility-service""" return self.__data @@ -199,17 +210,27 @@ def get_wait_times_detailed(self): this = {} try: if i['meta']['type'] != "RESTAURANT": + + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = i['meta']['type'].capitalize() times[id] = this except: + + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = "Entertainment" times[id] = this @@ -242,10 +263,15 @@ def get_attraction_wait_times_detailed(self): this = {} try: if i['meta']['type'] == "ATTRACTION": + + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = i['meta']['type'].capitalize() times[id] = this except: @@ -276,10 +302,15 @@ def get_entertainment_wait_times_detailed(self): id = i['id'].split("_")[-1] this = {} if 'type' not in i['meta'].keys(): + + update_time = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + update_time = update_time.replace(tzinfo=pytz.utc) + update_time = update_time.astimezone(self.__time_zone) + this['name'] = i['name'] this['status'] = i['status'] this['wait_time'] = i['waitTime'] - this['last_updated'] = datetime.strptime(i['lastUpdate'], "%Y-%m-%dT%H:%M:%S.%fZ") + this['last_updated'] = update_time this['entityType'] = "Entertainment" times[id] = this diff --git a/MouseTools/pointsofinterest.py b/MouseTools/pointsofinterest.py index d35648a..38f528d 100644 --- a/MouseTools/pointsofinterest.py +++ b/MouseTools/pointsofinterest.py @@ -1,9 +1,8 @@ import requests -import json -import sys -import sqlite3 +import pytz from datetime import datetime, timedelta from .auth import get_headers +from .ids import WDW_ID, DLR_ID class PointOfInterest(object): @@ -84,6 +83,13 @@ def __init__(self, id = None): except: self.__anc_ev_id = None + if self.__anc_dest_id == WDW_ID: + self.__time_zone = pytz.timezone('US/Eastern') + elif self.__anc_dest_id == DLR_ID: + self.__time_zone = pytz.timezone('US/Pacific') + else: + self.__time_zone = pytz.timezone('US/UTC') + def get_id(self): @@ -130,6 +136,10 @@ def get_links(self): """Returns a dictionary of related links""" return self.__data['links'] + def get_time_zone(self): + """Returns pytz timezone object""" + return self.__time_zone + def get_raw_data(self): """Returns the raw data from global-facility-service""" return self.__data diff --git a/setup.py b/setup.py index c127e7d..b93f540 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,10 @@ long_description_content_type="text/markdown", url="https://github.com/scaratozzolo/MouseTools", packages=setuptools.find_packages(), - install_requires=["requests"], + install_requires=[ + "requests", + "pytz", + ], classifiers=( "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License",