With my recent change of jobs, I finally had the energy and interest to write the script I’ve tweeted/written about in my previous Trello posts.
This script handles creating my weekly to do list card with seven checklists (one for each day of the week), my monthly sanity check of what bills I have to pay, and an annual card with a general grouping of things I need to remember to do at the end of each year.
The weekly and monthly checklists are created two weeks and one month ahead, respectively. This allows me to add things to the weekly checklists that are one offs, and check things off of the bills card as they auto-charge to my credit card. I am in a big push right now to be debt free by 30, so I’ve become rather obsessive about where every penny goes, this helps me feel better about that.
A couple of things about the creation of this script. First, it wasn’t a high pressure script, so even though I wrote the script a week ago, I didn’t really try to debug in any serious manner until yesterday. I just threw it up on the server and let the cron job run and send me the errors when it ran at midnight every night.
Second, it’s been ages since I wrote any php, but that’s the server scripting language I am most comfortable with. I’ve been working on several school projects in python, so the context switch came back to bite me more than once. Forgotten semi-colons, curly braces, you name it.
Plus, the Trello API is pretty insistent that it’s ‘idList’ when you’re creating a card array, not ‘idlist’. Crazy to have to follow directions, I know.
[php]
$card_data = array(
‘name’ => (‘To Do for Week of: ‘ . date(‘j F Y’, strtotime(‘+2 weeks’))),
‘idList’ => ‘<redacted>’,
‘labels’ => ‘yellow’,
‘pos’ => ‘top’
);
[/php]
Another hitch I ran into was that I am dumping getdate() into a variable, and had used numeric index instead of key value pairs to access the array.
[php]
$date_array = getdate();
//is it Sunday, first of the month, or 1 December?
if ($date_array[‘wday’] === 0 || $date_array[‘mday’] === 1 || ($date_array[‘mon’] === 12 && $date_array[‘mday’] === 1))
{…
[/php]
This caused the date evaluations I was using to determine whether it was Sunday, the first of the month, or December 1 to pass no matter what. My conditionals failed to gate anything, because $date_array[4] == 0 always evaluated to true because it was coming back as NULL, which can equal 0. So, it passed and then it failed on the fact that ‘l’ should have been ‘L’ in idList. Isn’t coding fun!?
"Invalid idlist value"
I would be remiss if I didn’t mention Clark Rasmussen here. He saw the bugs I missed in a few places, and also allowed me to use his Trello API script that gets the idList numbers for your columns, as well as his script that handles creating connections to the Trello API, so that was a load off my plate and allowed me to focus on creating the functionality I wanted. You can read more about his adventures with the Trello API here.
He also pointed me towards the date() function in php that replaced about 50-60 lines of logic to just get the date for the card’s title in my weekly card and the due date on my monthly card. Yay for learning!
[php]’due’ => date(‘Y-m-01 12:00 PM’, strtotime(‘+1 month’))[/php]
Now that I have properly debugged this script and it works, I have able to ditch my “Perma Cards” column, and since I figured out how to ditch the “food to try” column, I now have only 10 columns instead of 12. In addition, I weekly have my to do list created for me.
As well as my monthly bills card.
And my annual clean up/to do list.
All of which get placed at the top of the correct column with my ‘up next’ yellow label. It’s such a little time and space saver, but I am super glad to have finally written something I’ve been thinking about for months.
My next steps are going to be add my grocery list (because, yes, I am that lazy. Most programmers have little hacky scripts that automate the smallest things.) look at making it so that the script looks at which labels are where so that it can drop the cards directly under my green ‘in progress’ label cards, and I’m going to take a look at the Google Calendar API so that if I have one off things like my therapy, doctor, or other appointments that they will be added to my to do list card automatically.
Names of labels in listed cards is done via Chrome Extension, CSS Stylebot.
Leave a Reply