Monday, May 14, 2007

Wednesday, April 4, 2007

Update GTD-PHP from GMAIL

This Script Gets Action Items from Gmail and creates them in GTD-PHP.

copy and paste the code below into a text file called gmail2gtdphp.pl
you will need perl plus the Mail::Webmail::Gmail and WWW::Mechanize modules installed.


##########################################################################
# Name: gmail2gtdphp.pl
# About: This script scans you gmail account for actions that are marked
# as requiring action. It then populates those actions into
# gtd-php. if the email has 2 labels eg TBA and ProjectX
# then the action will be placed in the ProjectX project.
# Note the way I do this I think it will only work if the
# email is still in the inbox. if you have 3 labels on a email
# I will just use one at random and will eb unreliable.
# If an email has no label it will be stored inthe default
# project specified below.
#Usage:
# You will need to have projects in GTD-PHP that match label
# names in GMAIL at least for the ones you are likely to have
# actions against. if you have a label that is not in gtd-php
# it will just fail with an error.
#
# When you run the script it will get every message labelled
# as requiring action and import them into GTD-PHP it will then
# remove the action require label (except that part
# of WebMail::Gmail seems to be broken).
# You need to set some variables below
#
# Author: Michael Mueller
#
# Licence:
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself

use Mail::Webmail::Gmail;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();

#Set these following Variables to your requirements
#set the url of the php-gtd installation
#eg. my $url='http://www.example.net/gtd-php/'

my $url = '' ;
#gmail userid;
my $gmailUID = '';
#gmail password
my $gmailPass = '';
#Email requiring Action Label.
my $TBA = 'TBA';
#Default Project if no other label but TBA is present
my $defaultLabel = 'GMAIL';
#Contexts are just set to one value.
my $context = 'Computer';

#Shouldn't need to change anything past here.

my $gmail = Mail::Webmail::Gmail->new(
username => $gmailUID, password => $gmailPass,
);

my @labels = $gmail->get_labels();

my $messages = $gmail->get_messages( label => $labels[0] );
my $messages = $gmail->get_messages( label => $TBA );
foreach ( @{ $messages } ) {

my $id = $_->{id};
submit ($_);
$gmail->edit_labels( label => $TBA, action => 'remove', msgid => $id );


}

sub submit {
my( $this) = @_;

my $subject = $this->{'subject'};

my @labels = grep (!/$TBA/,@{$_->{'labels'}});
my $project = $labels[1];
if (!$labels[1]){$project = $defaultLabel}
$context = $context;
my $description = $this->{'blurb'};
my $type;

$type = '/item.php?type=a';
$mech->get( $url.$type );
$mech->submit_form(
form_number => 1,
fields => {
title => $subject,
description => $description,
projectId => $project,
contextId => $context,


}
);
}

GTD-PHP













I have been looking for a replacement to Next Action for tracking my tasks after it became way too when a lot of tasks got added. I tried Tack Coach for a bit but found it didn't present the tasks I need to do ina clear enough fashion. So after some Review I came across GTD-PHP a web based app which seems to do the trick. I hosted a copy on Burst and after making some small sql changes (Burst still uses mysql 4.0 something) I was off and running.
I find as soon as a task comes into my head I need to record it or its lost and the less resistance to recording the task the better so I wrote a small perl program that will add tasks to PHP-GTD with out me needing to open a web page etc. It only lets you enter the basic items required to create a new action and its very basic, I only spent an hour knocking it up.

To run it you will need Perl with the modules wxperl and WWW::Mechanize installed.

copy and paste the code below into a new file and save as gtdqa.pl. Follow the installation instructions at the top of the file.

#!/usr/bin/perl
#############################################################################
## Name: gtdqa.pl
## Purpose: Quickly Add new actions to GTD-PHP
## Author: Michael Mueller
## Modified by:
## Created: 05/04/2007
## Copyright: (c) 2007 Michael Mueller
## Based on a script a WX example script by Mattia Barbon
## Licence:
## This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
## Installation:
## You will need WX perl and WWW::Mechanize installed
## In the same Directory that this script is in you will require
## 3 files
## project.txt with the names of all your PHP-GTD projects
## one per line.
## context.txt with the names of all your PHP-GTD contexts
## one per line.
## config.txt with the url to your installation on the first line
## for example www.somwhere.com/php-gtd
## if you have your site password protected with basic AUTH
## you can do user:password@www.somwhere.com/php-gtd
## Usage:
## Run the Script "perlw gtdqa.pl" enter the subject and
## description of your task select the Project and Context
## Trouble Shooting:
## Note this script does no error checking if it does not
## seem to work run it in a cmd shell with perl gtdqa.pl
## and see if any thing is printed to shell when you try to add
## an action.
##
#############################################################################

use Wx;

package MyApp;

use strict;
use vars qw(@ISA);

@ISA=qw(Wx::App);

use Wx qw(wxDefaultSize wxDefaultPosition);

sub OnInit {
my( $this ) = @_;

my( $dialog ) = MyDialog->new( "wxPerl dialog sample",
wxDefaultPosition,
);

$this->SetTopWindow( $dialog );

$dialog->Show( 1 );

1;
}

package MyDialog;

use strict;
use vars qw(@ISA);
use WWW::Mechanize;
@ISA=qw(Wx::Dialog);
use FindBin qw($Bin);
use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
use Wx qw(wxDefaultSize wxDefaultValidator wxTE_MULTILINE);
my $mech = WWW::Mechanize->new();
my $config = loadParams($Bin.'config');
my $url = $config->[0].'/item.php?type=' ;


sub new {
my( $class ) = shift;
my( $this ) = $class->SUPER::new( undef, -1, 'PHP-GTD', [450, 250] );

# $this->SetIcon( Wx::GetWxPerlIcon() );
my $contexts = loadParams($Bin.'contexts');
my $projects = loadParams($Bin.'projects');
my( $ct ) = $this->{SUBJECT} =
Wx::TextCtrl->new( $this, -1, undef, [20, 20], [350, -1]);



my( $cb ) = Wx::Button->new( $this, -1, 'Submit', [300, 190] );


my( $p ) = $this->{PROJECT} = Wx::ComboBox->new( $this, -1, undef, [20,50],
[100,-1],
$projects );
my( $c ) = $this->{CONTEXT} = Wx::ComboBox->new( $this, -1, undef, [130,50],
[100,-1],
$contexts );

my( $ct ) = $this->{DESCRIPTION} =
Wx::TextCtrl->new( $this, -1, undef, [20, 80], [350, 100], wxTE_MULTILINE );

# my($cbx) = $this->{SOMEDAY} = ( $this, -1, 'Submit', [100, 200] );
# Wx::CheckBox->new($this, -1, 'Someday', [100, 200] );

EVT_BUTTON( $this, $cb, \&submit );

EVT_CLOSE( $this, \&OnClose );

$this;
}

sub submit {
my( $this, $event ) = @_;

my $subject = $this->{SUBJECT}->GetValue();
my $context = $this->{CONTEXT}->GetValue();
my $project = $this->{PROJECT}->GetValue();
my $description = $this->{DESCRIPTION}->GetValue();
my $type;
$type = 'a';
$mech->get( $url.$type );
$mech->submit_form(
form_number => 1,
fields => {
title => $subject,
description => $description,
projectId => $project,
contextId => $context,


}
);
$this->{SUBJECT}->SetValue('');
$this->{DESCRIPTION}->SetValue('');
}

sub loadParams
{
my ($fileName) = @_;
open (IF, $fileName.".txt")or die "Can not open File";
my @params = ;
chomp @params;
return \@params;
}


sub OnClose {
my( $this, $event ) = @_;

$this->Destroy();
}

package main;

my( $app ) = MyApp->new();

$app->MainLoop();

Hello

Don't expect much here its just a storage place for some GTD related items.