Skip to content

Commit

Permalink
add time zone data to object and last_update_time #11
Browse files Browse the repository at this point in the history
  • Loading branch information
scaratozzolo committed Dec 17, 2022
1 parent c55c532 commit 4aa6f4f
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 38 deletions.
24 changes: 18 additions & 6 deletions MouseTools/attractions.py
Original file line number Diff line number Diff line change
@@ -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



Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down
15 changes: 12 additions & 3 deletions MouseTools/characters.py
Original file line number Diff line number Diff line change
@@ -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



Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
41 changes: 34 additions & 7 deletions MouseTools/destinations.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')




Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
24 changes: 19 additions & 5 deletions MouseTools/entertainments.py
Original file line number Diff line number Diff line change
@@ -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



Expand Down Expand Up @@ -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')



Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down
16 changes: 13 additions & 3 deletions MouseTools/entertainmentvenues.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions MouseTools/facilities.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 4aa6f4f

Please sign in to comment.