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