Git Product home page Git Product logo

lapswim's Introduction

Lapswim

GitHub package.json version

Today's lap swim schedule at Baltimore's Waverly and Towson Ys in the terminal.

screenshot of lapswim cli

Schedules are scraped with Playwright, logged to stdout, and cached in a local json file for the day. The app is ran automatically by launchd on login and every 5 minutes.

Assumptions

  • macOS
  • jq installed via Homebrew at /opt/homebrew/bin/jq
  • Node.js installed via nvm at ~/.nvm
  • lapswim installed at ~/Code

Usage

  1. Clone lapswim
  2. Install dependencies
npm i
  1. Copy the sample plist file to your user agent directory and rename it
cp ./src/local.lapswim.plist.sample ~/Library/LaunchAgents/local.lapswim.plist
  1. Edit the Program and StandardErrorPath key values in ~/Library/LaunchAgents/local.lapswim.plist so the paths correspond to your machine
  2. Load the plist file with launchd
launchctl load ~/Library/LaunchAgents/local.lapswim.plist
  1. Set an alias in your terminal config file
# .zshrc, .bashrc, etc
alias swim='node ~/Code/lapswim/src/lapswim.mjs'
  1. Open a new terminal and run the swim alias to get today's lap swim times!
swim

> Saturday, December 2
>
> Waverly
> -------
> 7:00am-8:15am (3 lanes)
> 8:15am-12:30pm (1 lane)
> 12:30pm-6:30pm (3 lanes)
>
> Towson
> ------
> 7:00am-8:30am (6 lanes)
> 8:30am-12:00pm (4 lanes)
> 12:00pm-6:45pm (4 lanes)
>
> https://ymaryland.org/locations/weinbergy/weinbergschedules
> https://ymaryland.org/locations/orokaway/orokawaschedules

Resources

Contributing

Open a PR!

Author

Brian Zelip, https://zelip.me

License

GPLv3

lapswim's People

Contributors

brianzelip avatar

Stargazers

 avatar

Watchers

 avatar

lapswim's Issues

Handle alerts for possible closures

All Ys are closed today for some event, yet the schedule that this app scrapes doesn't reflect this. As a result the output from this app shows that there are three lap swim times today.

Check for alerts when scraping data and include any in the logged output.

Alerts are represented in a XHR response:

Request as URL

https://ymaryland.org/alerts?uri=/locations/weinbergy/weinbergschedules&_format=json

Request as fetch

await fetch("https://ymaryland.org/alerts?uri=/locations/weinbergy/weinbergschedules&_format=json", {
    "credentials": "omit",
    "headers": {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0",
        "Accept": "application/json, text/plain, */*",
        "Accept-Language": "en-US,en;q=0.5",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "Sec-GPC": "1",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache"
    },
    "referrer": "https://ymaryland.org/locations/weinbergy/weinbergschedules",
    "method": "GET",
    "mode": "cors"
});

Response:

{
  "header": {
    "local": [
      {
        "title": "Y ASSOCIATE APPRECIATION DAY CLOSING: OCTOBER 20th",
        "textColor": "000000",
        "bgColor": "FCAF17",
        "description": "<p>All Y family centers, program sites, classes, and activities will be closed on Friday, October 20 for Y Associate Appreciation Day. We encourage all of our associates to use this day to&nbsp;focus on their own well-being.&nbsp;Thank you for your understanding and support of our hard working team!</p>\r\n",
        "iconColor": "ED1C24",
        "linkUrl": null,
        "linkText": null,
        "id": "5458"
      }
    ]
  }
}

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.