Giter Site home page Giter Site logo

pirxpilot / liftie Goto Github PK

View Code? Open in Web Editor NEW
65.0 15.0 29.0 12.29 MB

:ski: Clean, simple, easy to read, fast ski resort lift status.

Home Page: https://liftie.info

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.01% JavaScript 0.77% Shell 0.01% HTML 99.14% Stylus 0.05% Pug 0.04%
lift-status javascript ski-resort

liftie's Introduction

NPM version Build Status Dependencies

liftie.info

Clean, simple, easy to read, fast ski resort lift status.

Features

  • Displays multiple resorts on a single page.

  • Refreshes automatically every 65 seconds.

  • Index page displays all supported resorts but it's possible to specify (and bookmark) a subset:

      https://liftie.info?resorts=alpine,palisades
    
  • REST type API returns a status of each resort.

      GET https://liftie.info/api/resort/<resort>
    
  • Status is cached on a server side. Regardless of the number of browser request, server will retrieve (and parse) the resort pages only once per minute.

How to run liftie locally

Clone this repo (or your fork)

git clone [email protected]:pirxpilot/liftie.git && cd liftie

Build client side scripts: make will install all external components and trigger component build for you.

make

Run and profit (liftie binds to port 3000 by default)

node app

How to add your favorite acme.com resort

Generate resort scaffolding

The easiest way to start working on a new resort is to run generate script.

$./bin/generate

The script expects the short (one word, dashes OK) identifier of the ski resort, the human readable name and the URL of the page with lift status. It also asks for resort geographical coordinates.

The following files are generated for a newly added resort:

  • resort descriptor lib/resort/acme/resort.json,
  • parser lib/resort/acme/index.js,
  • and a test for a parsing function test/resort/acme.js.
  • lift status page retrieved from internet test/resort/example/acme.html

You can check this commit to see what you can expect after this page is completed.

Newly added resort is displayed automatically on liftie index page, but it won't have any lifts at this stage.

Update test

Now you can flesh out the test by adding expected list of ski lifts. See this commit.

var expected = {
  'Super Express Lift': 'closed',
  'Magic Carpet': 'open',
  'Ultra Gondola': 'hold',
  'T-Bar': 'scheduled'
};

At this point you should probably run the tests: since parsing function is not implemented the test will fail.

You can run only the specific resort test by running:

make test TESTS="**/*/acme.js"

Implement parser

lib/resorts/acme/index.js exports the following object

module.exports = {
  selector: '.lifts',                // selector for lift information
  parse: {
    filter: node => node.children,   // if present skips nodes for which filter is falsy
    name: '0/1',            // example of a simple path descriptor (second child of the first child)
    status: {               // example of a compound descriptor
      child: '+/1',
      attribute: 'alt',
      regex: /-([a-z]+)$/,
      fn: s => s.slice(0, -3)
    }
  }
};

You need to adjust it to find the lift names and their statuses:

  • selector is a CSS selector that should locate the parent of the name and status elements
  • parse needs to contain 2 descriptors - one for name and the other for status
  • name and status descriptors have the following properties
    • child - dash-separated path to the name or status HTML element - index, ,, .., +, - are supported
    • attribute - optional - if specified the value of the attribute instead of the contents of the element is used
    • regex - optional - if specified the regex is executed and the value of the first matching group is used
    • fn - optional - if specified the function is called that can be used to convert the value

If child is the only part of the descriptor it can be used directly. In other words:

name: {
  child: '0/3'
}

is the same as

name: '0/3'

Check out this commit to see the simple parser implemented.

Once parser is ready the tests should succeed.

Improvements

  • improve weather - US resorts can have more precise weather forecast, if there is a NOAA station nearby: run bin/fetch-noaa --overwrite <resort-name> to find it
  • add webcams - normally just specifying position would add some webcams to the liftie page but you can also just add links to the webcams in resort.json descriptor

Alternative status source

In some cases the lift status info is not directly accessible on the web page to which liftie should be redirecting its users. For example lift status might be contained in an invisible iframe or retrieved from a 3rd party server. In such cases specify dataUrl in addition to the url entry in the resort descriptor.

Liftie will always use url to construct the link to the relevant resort page, and - if present - it will use dataUrl to retrieve the page that is subsequently parsed to obtain lift information.

Resort JSON API

In addition to parsing lift status pages Liftie supports resorts that make their lift status available through REST API. In such cases you need to specify api element in resort descriptor.

"api": {
  "host": "http://api.acme.com",
  "pathname": "/api/status"
}

If api is specified Liftie will retrieve status info through HTTP GET. The resort parse function will receive parsed json instead of the dom tree. Please note that you still need to configure url - it is used on Liftie pages to send users to official resort page. Check out this implementation, if you are looking for an example.

Credits

Icon Font generated with IconMoon App

Forecast Font from Icon Vault -- SIL Open Font License

Tags CSS (stylus) is a simplified version of Sliding Tags by Thibaut Courouble -- License MIT

License

3-Clause BSD License

liftie's People

Contributors

bclifton-exp avatar fezvrasta avatar jeffstieler avatar jinschoi avatar matthewhallcom avatar mdjong1 avatar melitele avatar miguelhughes avatar mikemmb73 avatar pirxpilot avatar readingdancer avatar romkabouter avatar srocki avatar williamhf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

liftie's Issues

Change JSON Structure

My reverse engineering skills aren't the greatest...I am trying to index the lift names and status, but since they aren't numbered, I’m having trouble. Is there a way to change it like described below?

Current:
Screen Shot 2021-12-24 at 10 08 57 PM
Suggested:
Screen Shot 2021-12-24 at 10 10 23 PM

Basically, just have each lift status have its own unique, numbered index rather than the name of the lift be the index.

Provide list endpoint

Hi, do you think you could add an api endpoint to retrieve all the resorts list with their info such as name coordinate etc?

Baqueira/​Beret

Hi, can anyone point me to the page where the skilifts status is held? I can't seem to find it anywhere 🤔 I'd like to add it to Liftie

Multiple (European?) resorts broken due to changed links

Multiple resorts appear to be broken due to links that have changed. This might be something Covid related, and could be different in the following season, so might not be high priority at the moment.

Resorts checked:

  • Les Arcs
  • La Plagne
  • Kitzbuehel
  • Les Menuires
  • Meribel

Help with resort?

Hi, could I get some help converting this into a resort matcher?

$$('[class*="impianto-status"]').map(x => ({
  name: x.parentNode.childNodes[0].innerText,
  status: (() => { switch (x.getAttribute("class").match(/impianto-status-([FPO])/)[1]) {
          case 'F': return 'closed';
          case 'P': return 'hold';
          case 'O': return 'open';
        }})()
}));

I have this but it's not working

module.exports = {
  selector: '[class*="impianto-status"]', // selector for lift information
  parse: {
    filter: (node) => node.children, // if present skips nodes for which filter is falsy
    name: '../0', // example of a simple path descriptor - index, ',', '..', '+', '-' are supported. Here 0/1 just means "use the second child of the first child."
    status: {
      // example of a compound descriptor child. attribute, regex, fn - can be specified
      child: '.',
      attribute: 'class',
      regex: /impianto-status-([FPO])/,
      fn: (s) => {
        switch (s[1]) {
          case 'F': return 'closed';
          case 'P': return 'hold';
          case 'O': return 'open';
        }
      }
    },
  },
};

Update Readme.md

Please update readme.md to support latest updates. How to add restorts... etc...

Makefile fails on win10

After running "yarn" executing "make" under Cygwin64 terminal fails with such errors :

_TypeError: Cannot read property 'slice' of null
at parseHeaders (G:\liftie\node_modules@pirxpilot\replay\src\catalog.js:32:55)
at parseRequest (G:\liftie\node_modules@pirxpilot\replay\src\catalog.js:69:19)
at Catalog._read (G:\liftie\node_modules@pirxpilot\replay\src\catalog.js:256:17)
at Catalog.find (G:\liftie\node_modules@pirxpilot\replay\src\catalog.js:195:28)
at G:\liftie\node_modules@pirxpilot\replay\src\recorder.js:15:32
at Function.layer [as next] (G:\liftie\node_modules@pirxpilot\replay\src\chain.js:50:7)
at G:\liftie\node_modules@pirxpilot\replay\src\chain.js:54:17
at G:\liftie\node_modules@pirxpilot\replay\src\logger.js:16:5
at Function.layer [as next] (G:\liftie\node_modules@pirxpilot\replay\src\chain.js:50:7)
at G:\liftie\node_modules@pirxpilot\replay\src\chain.js:54:17
Emitted 'error' event on PassThrough instance at:
at ProxyRequest.propagateError (G:\liftie\node_modules\getlet\lib\getlet.js:147:10)
at ProxyRequest.emit (events.js:322:22)
at Immediate. (G:\liftie\node_modules@pirxpilot\replay\src\proxy.js:121:16)
at processImmediate (internal/timers.js:456:21) {
code: 'CORRUPT FIXTURE',
syscall: 'connect'

10 tests
15 passed

Pass!
NODE_PATH=lib/client:node_modules
./node_modules/.bin/browserify
--require resort/lifts
--require resort/twitter
--require resort/weather
--require resort/webcams
--require resort/snow
--entry lib/client/boot/index.js
--outfile public/scripts/liftie.js
Error: Cannot find module 'resort/lifts' from 'G:\liftie'
at G:\liftie\node_modules\browser-resolve\node_modules\resolve\lib\async.js:46:17
at process (G:\liftie\node_modules\browser-resolve\node_modules\resolve\lib\async.js:173:43)
at ondir (G:\liftie\node_modules\browser-resolve\node_modules\resolve\lib\async.js:188:17)
at load (G:\liftie\node_modules\browser-resolve\node_modules\resolve\lib\async.js:69:43)
at onex (G:\liftie\node_modules\browser-resolve\node_modules\resolve\lib\async.js:92:31)
at G:\liftie\node_modules\browser-resolve\node_modules\resolve\lib\async.js:22:47
at FSReqCallback.oncomplete (fs.js:167:21)
make: *** [Makefile:48: public/scripts/liftie.js]_

Could you help and tell what am i doing wrong? Maybe there is a better way to make it work under windows.

Bug / Fix

There is an error that shows up while trying to create a mountain:

prompt: Short name of the resort [acme]:  mt-baw-baw
prompt: Human readable name of the resort [Acme Ski]:  Mount Baw Baw
prompt: URL of the resort website [http://acme.com]:  https://mountbawbaw.com.au/snow-and-weather-report
prompt: Comma separated list of tags [Colorado, Vail, New Hampshire]:  Victoria, Australia
prompt: Twitter handle (without @) [acme]:  MountBawBaw
prompt: Resort location [latitude, longitude]:  37.8383, 146.2736
prompt: Opening date [YYYY-MM-DD]:  0000-00-00
Generating files for Mount Baw Baw
Generating /Users/_/liftie/lib/resorts/mt-baw-baw/index.js...
Generating /Users/_/liftie/lib/resorts/mt-baw-baw/resort.json...
Generating /Users/_/liftie/test/resorts/mt-baw-baw.js...
Fetching https://mountbawbaw.com.au/snow-and-weather-report to /Users/oscargorog/liftie/test/resorts/example/mt-baw-baw.html...

(node:882) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
(node:882) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
(node:882) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.

boyne update

Tried to make a PR for this but was denied.
Anyways the fix for the Boyne resorts is below.
Tested on local instance and [brighton, big-sky, loon, sugarloaf, sunday-river] are all
working.

module.exports = { selector: 'div.liftStatus-lift-icon', parse: { name: '+/0', status: { child: '0', attribute: 'alt' } } };

Make

I install the lifitie code and yarn but once hitting make ran into this:

Is this still active

It's hard to tell given lifts are shut down, but the links provided are no longer active:

http://acme.com/lift/status

That leads to a dead end. I am assuming the api used just isn't active anymore, but maybe I am doing something wrong

Not sure how I would add resorts if I don't know the accurate names:

Short name of the resort [acme]:
Human readable name of the resort [Acme Ski]:
URL of the page with lift status [http://acme.com/lift/status]:

I tried by just making my own:

prompt: Short name of the resort [acme]:  Timberline
prompt: Human readable name of the resort [Acme Ski]:  Timberline Lodge
prompt: URL of the resort website [http://acme.com]:  https://www.timberlinelodge.com/
prompt: Comma separated list of tags [Colorado, Vail, New Hampshire]:  Timberline, Timberline Lodge, Oregon
prompt: Twitter handle (without @) [acme]:  timberlinelodge
prompt: Resort location [longitude, latitude]:  45.3311, -121.7110
prompt: Opening date [YYYY-MM-DD]:  2019-11-28
Generating files for Timberline Lodge
Generating /Users/stephenphillips/Desktop/liftie/lib/resorts/Timberline/index.js...
Generating /Users/stephenphillips/Desktop/liftie/lib/resorts/Timberline/resort.json...
Generating /Users/stephenphillips/Desktop/liftie/test/resorts/Timberline.js...
Fetching https://www.timberlinelodge.com/ to /Users/stephenphillips/Desktop/liftie/test/resorts/example/Timberline.html...
(node:72389) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.

This doesn't pass tests:

  1) parse Timberline
       should return lift status:

      Uncaught AssertionError: expected Object {} to equal Object { 'lift 1': 'open' }
      + expected - actual

      -{}
      +{
      +  "lift 1": "open"
      +}

Another ERROR...

This error is created while trying to run: node app:

module.js:540
    throw err;
    ^

Error: Cannot find module './resorts/.DS_Store/resort.json'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at /Users/oscargorog/liftie/lib/loader.js:11:20
    at Array.reduce (<anonymous>)
    at /Users/oscargorog/liftie/lib/loader.js:10:22
    at FSReqWrap.oncomplete (fs.js:135:15)

No Data Available

All reports don't appear to be populated by any lift data. Is this a known issue?

Cannot read properties of undefined (reading 'foreEach')

Index.js

var debug = require('debug')('liftie:resort:bad-kleinkirchheim');
module.exports = parse;

function parse(data) {
var liftStatus = {};

data.lifts.forEach(function(lift) {
liftStatus[lift.popup.title.trim()] = lift.status;
});

debug('bad-kleinkirchheim lift status:', liftStatus);
return liftStatus;
}

Resort.json

{
"name": "bad-kleinkichheim",
"url": {
"host": "https://winter.intermaps.com",
"pathname": "/bad_kleinkirchheim/data?lang=en"
},
"api": {
"host": "https://winter.intermaps.com",
"pathname": "/bad_kleinkirchheim/data?lang=en"
},
"tags": [
"austria"
],
"ll": [
null
]
}

I know that i shouldnt have to put in the api i like this, when it isnt an api link, however i was just testing out if data?lang=en or api might have been the issue.

Vail resorts do not work due to waiting room

Wildcat and Attitash(both owned by Vail I believe) both are missing data when their sites have it. I believe this is due to a browser issue from the scrape. When I try it, I receive a no javascript issue from not using an actual browser to access the site. Not sure how to get around it.

Cannot run generate script - & missing npm dependencies

Problem when trying to use the generate script

/(...)/liftie/bin/generate:158
schema[2].before = splitHost;
^
TypeError: Cannot read property '2' of undefined
at execute (/(...)/liftie/bin/generate:158:9)
at Object. (/(...)/liftie/bin/generate:44:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3

Had some problem when trying to npm / make as missing dependencies

npm WARN package.json [email protected] No repository field.
npm ERR! fetch failed http://registry.npmjs.eu/methods/-/methods-0.0.1.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 503
npm ERR! fetch failed http://registry.npmjs.eu/methods/-/methods-0.0.1.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 503
npm ERR! fetch failed http://registry.npmjs.eu/methods/-/methods-0.0.1.tgz
npm ERR! Darwin 14.1.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.10.36
npm ERR! npm v2.4.1

Latest version is 1.1.1 - 0.0.1 is outdated

  • on components when trying make 👍

node_modules/make-component-shrinkwrap/node_modules/.bin/component-shrinkwrap --install
make: node_modules/make-component-shrinkwrap/node_modules/.bin/component-shrinkwrap: No such file or directory
make: *** [components] Error 1

had to manually install latest versions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.