Changed join to price table to a LEFT JOIN so that I can also keep track of the Alamo restaurant operating hours with the same tables
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
import json, requests, psycopg2, logging
|
import json, requests, psycopg2, logging, sys
|
||||||
from psycopg2 import sql
|
from psycopg2 import sql
|
||||||
|
|
||||||
ATTRACTIONS_IO_ENDPOINT = "https://live-data.attractions.io/72f0ea9e-d196-508a-bee8-cce62c3228c7.json"
|
ATTRACTIONS_IO_ENDPOINT = "https://live-data.attractions.io/72f0ea9e-d196-508a-bee8-cce62c3228c7.json"
|
||||||
@@ -152,6 +152,15 @@ logging.info('Fetching most recent park hours entry from DB...')
|
|||||||
park_hours_pull = generic_query(park_hours_query)[0]
|
park_hours_pull = generic_query(park_hours_query)[0]
|
||||||
logging.debug('%s - %s', park_hours_pull[2], park_hours_pull[3])
|
logging.debug('%s - %s', park_hours_pull[2], park_hours_pull[3])
|
||||||
|
|
||||||
|
try:
|
||||||
|
closed = park_hours_pull[4]
|
||||||
|
except:
|
||||||
|
closed = False
|
||||||
|
|
||||||
|
if park_hours_pull[4]:
|
||||||
|
logging.info('Park closed today. Exiting...')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if park_hours_pull[2].date() == date.today():
|
if park_hours_pull[2].date() == date.today():
|
||||||
logging.info('Park hours for today already in DB')
|
logging.info('Park hours for today already in DB')
|
||||||
park_opens = park_hours_pull[2]
|
park_opens = park_hours_pull[2]
|
||||||
|
|||||||
Executable
+50
@@ -0,0 +1,50 @@
|
|||||||
|
WITH cte AS (
|
||||||
|
SELECT scrape_data._id,
|
||||||
|
scrape_data.is_operational,
|
||||||
|
scrape_data.queue_time,
|
||||||
|
scrape_data.queue_status_message,
|
||||||
|
scrape_data.is_open,
|
||||||
|
scrape_data.open_time,
|
||||||
|
scrape_data.close_time,
|
||||||
|
scrape_data.time_stamp,
|
||||||
|
row_number() OVER (PARTITION BY scrape_data._id ORDER BY scrape_data.time_stamp DESC) AS row_number
|
||||||
|
FROM knoebels."LZ_attractions_io" scrape_data
|
||||||
|
)
|
||||||
|
SELECT cte._id,
|
||||||
|
poi.name,
|
||||||
|
prices.price,
|
||||||
|
cte.is_operational,
|
||||||
|
cte.queue_time,
|
||||||
|
cte.queue_status_message,
|
||||||
|
cte.is_open,
|
||||||
|
cte.open_time,
|
||||||
|
cte.close_time,
|
||||||
|
cte.time_stamp,
|
||||||
|
rm.hand_stamp_included,
|
||||||
|
rm.bargain_night_included,
|
||||||
|
rm.capacity,
|
||||||
|
rm.duration,
|
||||||
|
poi.summary,
|
||||||
|
poi.keywords,
|
||||||
|
poi.default_image,
|
||||||
|
poi.location,
|
||||||
|
poi.featured,
|
||||||
|
poi.wayfinding_enabled,
|
||||||
|
poi.visible_on_map,
|
||||||
|
poi.category,
|
||||||
|
poi.minimum_height_requirement,
|
||||||
|
poi.minimum_unaccompanied_height_requirement,
|
||||||
|
poi.maximum_height_requirement,
|
||||||
|
poi.minimum_age_requirement,
|
||||||
|
poi.minimum_unaccompanied_age_requirement,
|
||||||
|
poi.maximum_age_requirement,
|
||||||
|
poi.restriction_summary
|
||||||
|
FROM cte
|
||||||
|
JOIN knoebels.ride_master rm ON cte._id = rm.attractions_dot_io_id
|
||||||
|
JOIN knoebels."LZ_attractions_io_poi" poi ON cte._id = poi._id
|
||||||
|
LEFT JOIN ( SELECT row_number() OVER (PARTITION BY ride_data_in.ride ORDER BY ride_data_in.time_stamp DESC) AS row_number,
|
||||||
|
ride_data_in.time_stamp,
|
||||||
|
ride_data_in.ride,
|
||||||
|
ride_data_in.price
|
||||||
|
FROM knoebels.ride_data_in) prices ON prices.ride = rm.ride AND prices.row_number = 1
|
||||||
|
WHERE cte.row_number = 1;
|
||||||
@@ -42,8 +42,11 @@ SELECT livedata.time_stamp
|
|||||||
,restriction_summary
|
,restriction_summary
|
||||||
--FROM knoebels."LZ_attractions_io" AS livedata
|
--FROM knoebels."LZ_attractions_io" AS livedata
|
||||||
FROM livedata
|
FROM livedata
|
||||||
|
--This POI data comes from a massive JSON file hosted by attractions.io the app downloads it on first launch. Not sure how often it's updated or only as-needed
|
||||||
JOIN knoebels."LZ_attractions_io_poi" AS poi ON livedata._id = poi._id
|
JOIN knoebels."LZ_attractions_io_poi" AS poi ON livedata._id = poi._id
|
||||||
|
-- This is my own "master" file for ride data, for data points not served by the attractions.io API. Handstamp inclusions/exclusions, capacity, duration, etc.
|
||||||
JOIN knoebels.ride_master rm ON livedata._id = rm.attractions_dot_io_id
|
JOIN knoebels.ride_master rm ON livedata._id = rm.attractions_dot_io_id
|
||||||
|
-- fetch most recent price data, scraped from webpage, this can differ from the POI data used by the app
|
||||||
JOIN (SELECT row_number() OVER (PARTITION BY ride ORDER BY time_stamp DESC) AS row_number, * FROM knoebels.ride_data_in) prices ON prices.ride = rm.ride and prices.row_number = 1
|
JOIN (SELECT row_number() OVER (PARTITION BY ride ORDER BY time_stamp DESC) AS row_number, * FROM knoebels.ride_data_in) prices ON prices.ride = rm.ride and prices.row_number = 1
|
||||||
--ORDER BY name, time_stamp
|
--ORDER BY name, time_stamp
|
||||||
--where name = 'Sklooosh'
|
--where name = 'Sklooosh'
|
||||||
|
|||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
WITH CTE AS (
|
||||||
|
SELECT *,
|
||||||
|
row_number() OVER (PARTITION BY scrape_data._id ORDER BY scrape_data.time_stamp DESC) AS row_number
|
||||||
|
FROM knoebels."LZ_attractions_io" scrape_data
|
||||||
|
)
|
||||||
|
SELECT CTE.time_stamp
|
||||||
|
,CTE._id
|
||||||
|
,poi.name
|
||||||
|
,CTE.is_operational
|
||||||
|
,CTE.is_open
|
||||||
|
,CTE.queue_status_message
|
||||||
|
,last_online.time_stamp AS last_online
|
||||||
|
FROM CTE
|
||||||
|
JOIN knoebels."LZ_attractions_io_poi" AS poi ON CTE._id = poi._id
|
||||||
|
JOIN knoebels.ride_master rm ON CTE._id = rm.attractions_dot_io_id
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT *,
|
||||||
|
row_number() OVER (PARTITION BY scrape_data._id ORDER BY scrape_data.time_stamp DESC) AS row_number
|
||||||
|
FROM knoebels."LZ_attractions_io" scrape_data
|
||||||
|
where is_operational = true and is_open = true
|
||||||
|
) AS last_online
|
||||||
|
ON CTE._id = last_online._id and last_online.row_number = 1
|
||||||
|
WHERE CTE.row_number = 1
|
||||||
|
AND (CTE.is_operational = false OR (CTE.queue_status_message IS NOT NULL AND CTE.queue_status_message != ''))
|
||||||
|
ORDER BY name;
|
||||||
Reference in New Issue
Block a user