Beeminding Urgency Load

What’s the easiest way to beemind my Urgency Load?
Is there an existing integration with IFTTT or Zapier or something like that?
I see that it’s returned by the API
I’d rather not reinvent the wheel!

4 Likes

I’m also trying to do this and would be interested in the approach others have taken. I’ve seen some discussions on the forum about implementations, but not many details about how to implement it.

This includes any scripts / tips that folks are willing to share (I’m using Python, but I’m a novice and don’t have any prior experience with URL handling).

My current thought is to schedule a timed job to fetch my urgency load at 11:59 pm and post that to a Do Less goal, with a rate of e.g. 65/day. Almost all of my goals are due at midnight right now, so this seems like a reasonable option. But I’ve also seen versions that aren’t cumulative / update more than once per day.

[Consider this a vote in favor off adding urgency load to the metaminder integration as well – it seems so useful for anyone with a lot of goals, it’s a shame it’s so hidden!]

2 Likes

I think Val Town could be a good tool for a quick and dirty solution if you’re willing to do a little coding. You can code the function on the site, no need for setting up a local environment, and also schedule it to run on a cron.

So it would be something like this:

async function updateUrgencyLoad() {
    const token = @me.secrets.BEEMINDER_AUTH_TOKEN;
    const base = 'https://www.beeminder.com/api/v1';
    const goal = 'load';

    const result = await fetch(
      `${base}/users/me.json?auth_token=${token}`
    );

    const { urgency_load } = await result.json();

    await fetch(
      `${base}/users/me/goals/${goal}.json?auth_token=${token}`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        value: urgency_load,
        requestid: (new Date()).toISOString().split('T')[0]
      })
    });
}

Haven’t tested it, but I think that’s close.

Reference:

If you’d rather not do any coding, I think Make.com has this use case covered, too.

8 Likes

Thanks! Val Town looks super, and I didn’t know that Make supports arbitrary API calls. I don’t think I’ll get back to this until the weekend, but I plan to check both out.

3 Likes

I’m currently beeminding this manually; I’m not sure yet how annoying that may prove to be.

You can see your urgency load across all goals in the Statistics tab on any goal page.

3 Likes

Following up, it seems like I’ve gotten Val Town to work!

I’m not sure what the difference is with narthur’s code, but after some fiddling this version suddenly started working, so I’m not touching it anymore :slight_smile:

async function updateUrgencyLoad() {
  const token = @me.secrets.BEEMINDER_AUTH_TOKEN;
  const base = 'https://www.beeminder.com/api/v1'
  const goal = 'urgency_load'
  
  // Retrieve urgency load value
  const response = await fetch(
    `${base}/users/me.json?auth_token=${token}`,
  );
  const data = await response.json();
  const urgencyLoad = data.urgency_load;

  // Post to goal
  await fetch(
    `${base}/users/me/goals/${goal}/datapoints.json`,
    {
      method: "POST",
      body:
        `auth_token=${token}&value=${urgencyLoad}&comment='posted by Val Town script'`,
      headers: { "Content-Type": "application/json" },
    },
  );
  console.log("Urgency load updated successfully");
}

I also checked out Make and it looked like the sort of thing that’s easy to use. But the UI ended up being more confusing to me than just dealing with the API directly.

6 Likes

Thanks to Nathan’s hints, I quickly got it working in Make (which I agree has a confusing UI) and then in a script that I now run regularly using LaunchControl (decent UI for the Mac’s equivalent of cron).

Script for interest, with my username and goalname hardcoded :man_facepalming:, but it boils down to two lines: fetch the urgencyload, create a datapoint.

#!/usr/bin/env perl

use warnings;
use strict;

our $beemuser;
require "$ENV{HOME}/lib/beemapi.pl";
require "$ENV{HOME}/lib/util.pl";

# check last value 
my $lasturgency = 0;
my $filename = "$ENV{HOME}/tmp/urgencyload";
if (open ( my $fh, '<:encoding(UTF-8)', $filename)) {
  $lasturgency = <$fh> || 0;
  close $fh;
}


my $urgency = beemuserfetch( 'pjh' )->{urgency_load};
print "Urgency load: $urgency\n";


# only send to Beeminder if it's changed
exit 0 if $urgency == $lasturgency;

beemcreate( 'pjh', 'urgency', time, $urgency, 'Entered by bmndr.urgency');
print "Successfully sent to Beeminder\n";

if (open ( my $fh, '>:encoding(UTF-8)', $filename)) {
  print $fh $urgency;
}
4 Likes