$|=1;
use strict;
use LWP::Simple;
use JSON;
use RTFUtil;
my $content = get("http://www.nozbe.com/api/projects/key-here_your_key");
print "$content\n";
my $json = new JSON;
my $projects = $json->decode($content);
print "\n ---\n";
print "".@$projects."\n";
open FILE, ">tareas.txt" or die $!;
rtf_create("tareas.rtf");
my $num=1;
foreach my $project (@$projects) {
print $$project{name}."\n";
print FILE " == ".$$project{"name"}." (".$$project{count}.") ==\n";
rtf_print_bold(" == ".$$project{"name"}." (".$$project{count}.") ==");
if($$project{count}==0){next;}
$content = get("http://www.nozbe.com/api/actions/what-project/id-".$$project{"id"}."/key-here_your_key");
my $tasks = $json->decode($content);
foreach my $task (@$tasks) {
if($$task{done}==0){
print FILE $num.". ".$$task{name}."\n";
rtf_print($num++.". ".$$task{name});
}
}
print FILE "\n";
rtf_print();
}
rtf_close();
You can see the Nozbe API here and your key here in the extra section under the API key label (to replace "here_your_key" in the code).
It would be fantastic to have this functionality directly available in the web interface.
Cheers.
Updated: Now done tasks are not included.
3 comentarios:
Can you provide some additional details or point to a resource for novices. Where would I store this pearl file and how would I run it. I assume it has something to do with the API, but I don't know how your file would be related to it. Thanks, John
Hi,
It's a bit complex for a person not used to program in Perl. I'll describe here the steps but probably you will have to search Internet (in concrete to install some modules of Perl needed by the program).
1. Install Perl, get Perl for Windows from ActiveState.
2. save the code in a file with extension .pl (i.e. "Nozbe_tasks.pl")
3. change in the code the text "here_your_key" with your key, see API key in the Extras! section of Nozbe.
4. After that if you try to execute the .pl file ("Nozbe_tasks.pl" in the example) you get and error message informing that some modules are missing. Probably "RTFUtil" and I'm not sure about "JSON". Here is where you have to execute "ppm" in a windows command line (cmd.exe).
That's the step a bit complex and probably you can find information about how to do it in Internet.
After that if you execute the Perl script the program generates a couple of files: "tareas.txt" and "tareas.rtf" (ups! Spanish :)) with all the tasks.
Hope it helps!, but I know it's a bit complex for a person not used to this environment.
regards,
Edu
I have created a version of the script for Mac (that works more or less in Mac, if you try to read the rtf in Windows there is no newline :-S)...
It uses RTF::Writer instead of RTFUtil, which seems it's not available in Mac/UNIX.
so, here it is:
#!/usr/bin/perl
$|=1;
use strict;
use LWP::Simple;
use JSON;
use RTF::Writer;
my $content = get("http://www.nozbe.com/api/projects/key-here_your_key");
print "content: $content\n";
my $json = new JSON;
my $projects = $json->decode($content);
print "\n ---\n";
print "".@$projects."\n";
open FILE, ">tareas.txt" or die $!;
my $rtf = RTF::Writer->new_to_file("tareas.rtf");
$rtf->prolog('fonts'=> [ "Calibri", "Cambria","Lucida Sans"]);
$rtf->prolog('colors'=> [undef, [172,82,8]]);
$rtf->number_pages;
my $num=1;
foreach my $project (@$projects) {
print($$project{name}."\n");
print FILE " == ".$$project{"name"}." (".$$project{count}.") ==\n";
$rtf->paragraph(\'\b'," == ".$$project{"name"}." (".$$project{count}.") ==");
if($$project{count}==0){next;}
$content = get("http://www.nozbe.com/api/actions/what-project/id-".$$project{"id"}."/key-here_your_key");
my $tasks = $json->decode($content);
foreach my $task (@$tasks) {
if($$task{done}==0){
if("$$task{next}" eq "next"){
$rtf->printf(\'{\i\cf1 (^) ');
}else{
$rtf->printf(\'{')
}
print FILE $num.". ".$$task{name}."\n";
$rtf->printf(\' %s }', $num++.". ".$$task{name}."\n");
}
}
print FILE "\n";
$rtf->print("\n");
}
$rtf->close();
Publicar un comentario en la entrada