npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sleepsecure

v0.0.2

Published

A lightweight scraper for SleepCycle's online SleepSecure data.

Downloads

6

Readme

sleepsecure

One of my favourite smartphone apps is SleepCycle; it records details of your sleep-quality using your phone's microphone and accelerometer, and tracks changes in that quality over time.

In addition, they offer a paid service that uploads your sleep-data to their servers, titled “SleepSecure.” Unfortunately — despite repeated inquiries over the last six(!) years — Northcube has never found the time or developer resources to expose any sort of official API for that sleep- data. )=

In the interim, thus, I've written a little scraping-tool: given a SleepSecure login and password, I can extract sleep-data via HTML-scraping of the SleepSecure dashboard.

Caveats

It's important to understand that this is not an API client. There is no official SleepSecure API. This is a scraping tool, which means that it's hitting Northcube's servers in a way for which they were not designed.

Based simply on the load-time of the SleepSecure dashboard, I'm pretty sure their web-app isn't exactly performance-optimized — and I have no idea what sort of server resources they're paying for. Take a gander at the “Basic Web Scraping Etiquette” section of Sebastian Wain's ‘Ultimate Guide to Web Scraping’; and attempt some backing-off behaviour if requesting information from their servers fairly often.

(You reading this, Northcube? Feel free to open an Issue if you'd prefer this operated in a different way! I'm happy to cooperate! <3)

Usage

This module exposes a single class; let's call it Session:

import SleepSecureSession from 'sleepsecure'

Each Session requires log-in information:

const sss = new SleepSecureSession('[email protected]', 'snicker snicker sekrit')

One of the primary purposes of the library is to handle persistence of the login cookies necessary to make requests, and re-authentication whenever that token expires. Generally speaking, you don't need to explicitly instruct the library to log-in — however, if you want to pre-emptively ensure logging-in is successful, you can explicitly issue a call to ::login():

if (!(await sss.login()))
   console.error("Unable to log in! Double-check your username and password?")

The cookies default to being stored according to the XDG spec (generally, under ~/.cache); but a specific filename can be provided as configuration:

new SleepSecureSession('someone', 'wizardry', { cookie_store_path: '~/.sleepsecure.txt' })

More specific methods are presumably forthcoming; but at the moment, the only interface to SleepSecure's data that is provided is a wrapper around bhttp's ::request() function, that additionally handles authentication and session-management:

sss.request("/site/comp/calendar")
.then(function(response){
   const $ = cheerio.load(response.body)

   $('tr:not(:nth-child(1))', 'table').each(function(){
      const date = $('.description > a', this).text()
          , quality = $('.value', this).first().text()

      console.log(`On ${date}, my sleep quality was ${quality}.`) }) })