themeparks

repository·master·Indexed 20 days ago

https://github.com/cubehouse/themeparks

An unofficial API library for accessing ride wait times and park opening times for 62 theme parks worldwide, including Disney, Universal, and SeaWorld. The library provides a unified interface via the Themeparks.Parks namespace to retrieve real-time wait times and operating schedules as Promises.

Tokens
16.7K
Snippets
56
Records
63
Agent score
68%

What's inside themeparks

  1. Enable debug mode

    master

    You can enable debug mode using the standard NODE_DEBUG environment variable. Pass themeparks to see debug logs during execution.

    To debug an online test:

    NODE_DEBUG=themeparks npm run testonline

    To combine multiple environment variables (e.g., debugging a specific park):

    NODE_DEBUG=themeparks PARKID=UniversalStudiosFlorida npm run testonline
  2. Run unit and online tests

    master

    The library uses mocha for testing. You can run offline functional unit tests or online tests that verify actual connections to park APIs.

    Offline Unit Tests Run these to test the library's logic without making network requests:

    npm test

    Or run against source files directly:

    npm run testdev

    Online Tests Run these to check if the library still connects to park APIs correctly:

    npm run testonline

    To test a specific park during an online test, set the PARKID environment variable:

    PARKID=UniversalStudiosFlorida npm run testonline
  3. How Schedule caching works

    master

    The Schedule class automatically manages its own persistence via an internal Cache instance.

    1. Initialization: When a Schedule is created, it calls CheckCacheStatus(). This returns a Promise that resolves once the cache has been successfully read from storage.
    2. Automatic Writes: Whenever SetDate or SetRange modifies the schedule, the class calls RequestCache(), which schedules a write to the cache after a 500ms debounce period.
    3. Data Retention: During a write, the class automatically purges schedule data older than 3 days to keep the cache size manageable.
    4. Manual Access: You can access the underlying cache instance via the Cache getter.
  4. Configure themeparks global settings

    master

    You can modify global library behavior by editing the properties of the Themeparks.Settings object. These settings affect caching and request timeouts.

    // Example of setting a custom cache location
    const Themeparks = require("themeparks");
    Themeparks.Settings.Cache = __dirname + "/themeparks.db";
  5. How SixFlagsPark handles ride status and wait times

    master

    The FetchWaitTimes() method retrieves ride status and wait times from the SixFlags API. It maps the API's status strings to internal status and wait time values:

    API StatusInternal StatusWait Time Value
    AttractionStatusOpenOperatingInteger (minutes)
    AttractionStatusClosedClosed-1
    AttractionStatusTemporarilyClosedDown-2
    AttractionStatusClosedForSeasonClosed-1
    AttractionStatusComingSoonClosed-3
    Other/UnknownDown-1
  6. Access available theme parks via AllParks or Parks

    master

    The library provides two ways to access the collection of supported theme park modules:

    1. AllParks: An array containing all available park modules. This is useful for iterating through all supported parks.
    2. Parks: A keyed object where each property name corresponds to a specific park module. This is useful for direct access to a specific park by its identifier.

    Each park module in these collections provides the API for interacting with that specific theme park's data (e.g., ride wait times, schedules).

    const { AllParks, Parks } = require('themeparks');
    
    // Iterate through all parks
    AllParks.forEach(park => {
      console.log(park.name);
    });
    
    // Access a specific park directly
    const magicKingdom = Parks.WaltDisneyWorldMagicKingdom;
    console.log(magicKingdom.name);
  7. Configure a Park implementation

    master

    When creating a new park implementation by extending the Park class, you can pass an options object to the constructor to configure caching behavior, network settings, and scheduling.

    Available Options:

    • cacheWaitTimesLength (Number, default: 300): Time in seconds to cache ride wait times.
    • cacheOpeningTimesLength (Number, default: 3600): Time in seconds to cache park opening times.
    • useragent (String|Function): A static User-Agent string or a generator function (compatible with random-useragent) to use for HTTP requests.
    • proxyAgent (http.Agent): An HTTP Agent object (e.g., https-proxy-agent) to use as a proxy for all requests made by this park instance.
    • scheduleDaysToReturn (Number, default: 60): The number of days the park's schedule should cover.

    Note: You cannot instantiate the Park class directly; you must use a specific park implementation.

    const MyPark = require('./my-park-implementation');
    
    const park = new MyPark({
      cacheWaitTimesLength: 600,
      cacheOpeningTimesLength: 7200,
      useragent: 'MyCustomUserAgent/1.0',
      proxyAgent: myProxyAgent,
      scheduleDaysToReturn: 30
    });
  8. Initialize a DisneyTokyoPark instance

    master

    To use the Tokyo Disneyland API framework, you must instantiate a class that extends DisneyTokyoPark. The constructor requires a parkId and fallbackEnglishNames to function correctly. You can optionally provide an apiKey, apiAuth, apiOS, apiBase, and apiVersion to override defaults.

    Required Options:

    • parkId: The Tokyo Disneyland API park ID (e.g., for a specific park).
    • fallbackEnglishNames: An object mapping facility codes to English ride data, used when scraping the official website fails.

    Optional Options:

    • apiKey: The API key for authentication.
    • apiAuth: The API authentication string.
    • apiOS: The operating system string (defaults to Android 9).
    • apiBase: The base URL for the API (defaults to https://api-portal.tokyodisneyresort.jp).
    • apiVersion: The API version string (defaults to 1.1.7).
    • timezone: The timezone for the park (defaults to Asia/Tokyo).
    const DisneyTokyoPark = require('./path/to/disneyTokyoBase');
    
    const myPark = new DisneyTokyoPark({
      parkId: 'some_park_id',
      fallbackEnglishNames: {
        244: { name: 'Space Mountain', area: 'Tomorrowland' }
      }
    });
  9. Instantiate and iterate over all available parks

    master

    To use the library, you can import themeparks and iterate over its Parks collection to instantiate specific park objects. This is useful for pre-loading park data into memory for fast access.

    const ThemeParks = require("themeparks");
    
    // construct our park objects and keep them in memory for fast access later
    const Parks = {};
    for (const park in ThemeParks.Parks) {
      Parks[park] = new ThemeParks.Parks[park]();
    }
    
    // print each park's name, current location, and timezone
    for (const park in Parks) {
      console.log(`* ${Parks[park].Name} [${Parks[park].LocationString}]: (${Parks[park].Timezone})`);
    }
  10. Use a proxy with a park object

    master

    If you need to route requests through a proxy, pass a proxyAgent (an instance of an http.Agent) in the options object when constructing a park class.

    // include the Themeparks library
    const Themeparks = require("themeparks");
    
    // include whichever proxy library you want to use (must provide an http.Agent object)
    const SocksProxyAgent = require('socks-proxy-agent');
    
    // create your proxy agent object
    const MyProxy = new SocksProxyAgent("socks://socks-proxy-host", true);
    
    // create your park object, passing in proxyAgent as an option
    const DisneyWorldMagicKingdom = new Themeparks.Parks.WaltDisneyWorldMagicKingdom({
        proxyAgent: MyProxy
    });
  11. Get ride wait times and park opening times

    master

    To access data, instantiate a specific park class from Themeparks.Parks.

    Important: Create the park object once and reuse it for the lifetime of your application. Re-creating the object frequently is slow and causes unnecessary data fetching.

    Use .GetWaitTimes() to retrieve ride wait times as a Promise, and .GetOpeningTimes() to retrieve park opening hours.

    // include the Themeparks library
    const Themeparks = require("themeparks");
    
    // access a specific park
    // Create this *ONCE* and re-use this object for the lifetime of your application
    const DisneyWorldMagicKingdom = new Themeparks.Parks.WaltDisneyWorldMagicKingdom();
    
    // Access wait times by Promise
    const CheckWaitTimes = () => {
        DisneyWorldMagicKingdom.GetWaitTimes().then((rideTimes) => {
            rideTimes.forEach((ride) => {
                console.log(`${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
            });
        }).catch((error) => {
            console.error(error);
        }).then(() => {
            setTimeout(CheckWaitTimes, 1000 * 60 * 5); // refresh every 5 minutes
        });
    };
    CheckWaitTimes();