Forums

Discuss all things Remember The Milk.

Repeating task for subsequent lessons in a course

daniel.hershcovich says:
I listen to audio courses to learn languages a lot, and I have a daily task in RTM to learn the next lesson. The task is tagged #audiocourse.

The lessons are numbered, though, and for a while I kept forgetting which lesson I'm at (because I was doing several courses in parallel, and because I don't have such a good memory). So I decided to include the lesson number in the task name.

However, when I complete the daily task (say, for lesson number 8), a new task is automatically created for the next day, but with the same name - that is, the same number (again 8). To solve this problem, I used to manually edit the task name and increment the lesson number (to 9 here), but eventually I wrote a Perl script that does it instead.

My script uses the RTMAgent Perl module (http://www.rutschle.net/rtm), and is very simple: when a completed task tagged #audiocourse has the same name as an incomplete task that is also tagged #audiocourse, and the name contains a number, the incomplete task is renamed, incrementing the number.

I scheduled my script to run daily, so now I just have to do my lesson, complete the task, and I never forget which lesson I'm at :)
Posted at 7:57pm on March 2, 2011
raymond.bergmark Power Poster says:
Really clever! If I were to decide this, this tip would be the next Tips&Tricks Tuesday winner.

Could you please post the script or a link to where to find it.

RTM: This would be a great thing to incorporate in future developments, a check box for auto-numbering subsequent tasks.
Posted 14 years ago
daniel.hershcovich says:
Sure - this is my script:
#!/usr/bin/perl

use WebService::RTMAgent;
use Getopt::Long;

sub usage()
{
print <<"EOF";
Usage: $0 [options]
Options are:
--auth Show code to authroize application
--quiet Disable prints
--verbose Show extra network information
--help Show this message
EOF
exit;
}

my ($auth,$quiet,$notify,$verbose,$help) = (0,0,0,0);
GetOptions ('authorize!' => \$auth,
'quiet!' => \$quiet,
'verbose!' => \$verbose,
'help' => \$help)
or usage();
usage if $help;

my $ua = WebService::RTMAgent->new;
$ua->verbose('netin netout') if $verbose;
$ua->api_key('');
$ua->api_secret('');
$ua->init;

if ($auth)
{
my $url = $ua->get_auth_url;
print "Please authenticate in this URL:\n$url\n";
exit;
}

sub is_completed_audiocourse_task($)
{
my ($taskname) = @_;
my $res = $ua->tasks_getList(
qq|filter=list:audiocourse AND status:completed AND name:"$taskname"|);
die $ua->error unless defined $res and $res->{stat} eq 'ok';

for my $tasks (@{$res->{tasks}}) {
for my $list (@{$tasks->{list}}) {
for my $taskseries (@{$list->{taskseries}}) {
return 1 if $taskseries->{name} eq $taskname;
} } }
return 0;
}

my $res = $ua->tasks_getList(
qq|filter=list:audiocourse AND status:incomplete|);
die $ua->error unless defined $res and $res->{stat} eq 'ok';

for my $tasks (@{$res->{tasks}}) {
for my $list (@{$tasks->{list}}) {
for my $taskseries (@{$list->{taskseries}}) {
for my $task (@{$taskseries->{task}})
{
next unless my ($basename, $number) =
$taskseries->{name} =~ /^(.*?\s+)(\d+)$/
and is_completed_pimsleur_task $taskseries->{name};
$number++;
my $name = $basename . $number;
my $res = $ua->tasks_setName("list_id=$list->{id}",
"taskseries_id=$taskseries->{id}",
"task_id=$task->{id}",
"name=$name");
die $ua->error unless defined $res;
my $message = qq|Renamed "$taskseries->{name}" to "$name"\n|;
print $message unless $quiet;
}
} } }
Posted 14 years ago
daniel.hershcovich says:
Sorry, the function call near the end should be "is_completed_audiocourse_task" - I didn't want to expose the name of the audiocourse :)
Posted 14 years ago
Log in to post a reply.