Year in review graph option

Inspired by @chelsea 's blog post (http://blog.beeminder.com/easythings/), I would like to do a review of my year as many of my goals have been running for longer than that.
Still, that means changing settings to 15-20 goals and then changing them back.

Would be nice if something could be hacked in in the next few days :slight_smile:

2 Likes

Your wish is my challenge… :slight_smile:

#!/bin/sh

# from https://www.beeminder.com/api/v1/auth_token.json
AUTH_TOKEN=your_token
USER=your_username

for GOAL in $( curl https://www.beeminder.com/api/v1/users/$USER.json?auth_token=$AUTH_TOKEN | sed -e 's/[^[]*//; s/^.//; s/].*//; s/[",]/ /g' )
do
  echo $GOAL
  curl -X PUT -d '{"tmin":"2016-01-01"}' https://www.beeminder.com/api/v1/users/$USER/goals/$GOAL.json?auth_token=$AUTH_TOKEN --header "Content-Type: application/json" > /dev/null
done

Using the undocumented tmin field in the API.

5 Likes

Thank you, will try it out!!

This seems like something I can use instead of my requested featured for a relative X-min value

2 Likes

This sounds so awesome, but I have no idea how to use it. Can you give me a place to start? Like what is this written in and what do I do with it to make it run?

2 Likes

Hey there tall girl. That’s a hard question to answer without knowing what you know, so what follows is going to be a really lousy answer. Apologies in advance. Hope it gives you a place to start, and maybe sparks a whole new learning quest for 2017.

That’s a unix shell script, a little program that I wrote on my Mac using a text editor (vim) in the Terminal app. If that sentence is mostly gibberish, there’s a learning curve ahead.

If you’re on a Mac, the simplest way to run it is probably to copy it into a plain text file in your home folder, replace the your_token and your_username bits, and then, in Terminal, type sh my_text_file.txt and press return.

If you’re not on a Mac, then that’s probably not very helpful, sorry. But you’re an old hand at setting up Beeminder goals, so if learning to program using the command line is important, you know what to do… :slight_smile:

Of course, running random bits of code from the internet without understanding what it’s going to do can be super dangerous. This script asks Beeminder for a list of all of your goal names, then for each one, asks Beeminder to change the graph’s start date. But you shouldn’t take my word for that.

2 Likes

Ah, yes. The embarrassing email addresses we chose at the age of 12.

Those words make sense to me, and I think I could totally follow your further instructions, if I only had a Mac.

I’ll see if I can get a virtual machine version of Linux running on my Windows computer and go from there. Thanks for the help!

1 Like

So glad to hear that it was at least vaguely helpful. I never know how much egg-sucking to include without inadvertently crossing into patronising.

There must be better ways on Windows to use our API. I just don’t know what they are. But someone here probably does.

15+ years ago, I would have suggested trying ‘cygwin’, which provided a unix shell-like layer overtop of w2k. There might be a modern equivalent, something that makes it easy to use the same script (even though it’s a quick and dirty hack). But a VM will do the trick if it’s easy.


PS: one of my brothers still has an elvish email address that dates from when he was around the same age…

1 Like

You were remarkably helpful, given that my question was extremely vague and I gave little to no indication of my prior experience. Thanks for being patient with me.

1 Like

Script worked like a charm! :slight_smile:

2 Likes

This was exactly what I was looking for this morning! Thanks @philip!

2 Likes

@philip, Do you think you might be able to help me out with this?

n00b question: If I’ve got this, how do I get the STARTRANGE variable where 2019-01-12 is? I’ve tried a few of the things I know from other languages, and my guess is that the problem I’m having has to do with single vs. double quoting, but that’s where I hit a brick wall, and I’d love to fix it, because this would make it so that every time I run it, all of my goals would show the last 85 days.

#!/bin/sh

# from https://www.beeminder.com/api/v1/auth_token.json
AUTH_TOKEN=yeAhRiGHt
USER=myusername

STARTRANGE="$(date -v-84d '+%Y-%m-%d')"

for GOAL in $( curl https://www.beeminder.com/api/v1/users/$USER.json?auth_token=$AUTH_TOKEN | sed -e 's/[^[]*//; s/^.//; s/].*//; s/[",]/ /g' )
do
  echo $GOAL 
  curl -X PUT -d '{"tmin":"2019-01-12"}' https://www.beeminder.com/api/v1/users/$USER/goals/$GOAL.json?auth_token=$AUTH_TOKEN --header "Content-Type: application/json" > /dev/null
done

Try this:

curl -X PUT -d "{\"tmin\":\"$STARTRANGE\"}" https://www and so on and so forth

Thanks. That didn’t do it, though!

Hi Mary! Definitely a quoting problem, as you suspected. As you know, single quotes don’t expand variables, but double quotes do. Of course, those are plain ascii quotes, not newfangled ‘smart’ quotes, which sometimes trips me up.

The current line in my script looks like this, with the date in $TMIN:

curl -# -X PUT -d "{\"tmin\":\"$TMIN\"}" https://www.beeminder.com/api/v1/users/$username/goals/$GOAL.json?auth_token=$auth_token --header "Content-Type: application/json" > /dev/null

Unfortunately, that looks remarkably like @phi’s suggestion, so I can only say that it works for me on my mac. I can’t read the error message in your images, so can’t begin to suggest what’s gone wrong.

My current tmin.sh script uses that pattern, if you want to download a working example.

2 Likes

That did it! Thanks @philip!!!

1 Like