Commit 7d2b8c1a7373aa934f1ec98d5ea8ae12557c2811
- Diff rendering mode:
- inline
- side by side
timelog-update-tasks
(46 / 0)
|   | |||
| 1 | #!/usr/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use feature 'say'; | ||
| 5 | use lib '/home/joenio/perl5/share/perl/5.10.0/'; | ||
| 6 | use WWW::Mechanize::TWiki; | ||
| 7 | use HTML::Entities; | ||
| 8 | use File::Slurp; | ||
| 9 | use Term::ReadPassword; | ||
| 10 | use utf8; | ||
| 11 | |||
| 12 | my $mech = WWW::Mechanize::TWiki->new(agent => 'colivre-robot', autocheck => 1 ) or die $!; | ||
| 13 | $mech->cgibin('http://www.colivre.coop.br/bin', { scriptSuffix => '' }); | ||
| 14 | |||
| 15 | sub logon { | ||
| 16 | my ($username, $password) = @_; | ||
| 17 | print STDERR "logon... "; | ||
| 18 | $mech->get('https://www.colivre.coop.br/bin/login/'); | ||
| 19 | $mech->form_name('loginform'); | ||
| 20 | $mech->field('username', $username); | ||
| 21 | $mech->field('password', $password); | ||
| 22 | $mech->submit(); | ||
| 23 | say STDERR "ok"; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub topic2timelog_tasks { | ||
| 27 | my $topic = shift; | ||
| 28 | print STDERR "acessando $topic... "; | ||
| 29 | $mech->get("/$topic"); | ||
| 30 | say STDERR "ok"; | ||
| 31 | return $mech->response->decoded_content; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub concat_tasks { | ||
| 35 | my $remote_tasks = shift; | ||
| 36 | my $local_tasks = read_file('/home/joenio/doc/todo'); | ||
| 37 | open TASKS, '>:utf8', '/home/joenio/.gtimelog/remote-tasks.txt'; | ||
| 38 | say TASKS $remote_tasks, $local_tasks; | ||
| 39 | close TASKS; | ||
| 40 | } | ||
| 41 | |||
| 42 | print 'wikiname: '; chomp(my $username = <STDIN>); | ||
| 43 | my $password = read_password('senha: '); | ||
| 44 | logon($username, $password); | ||
| 45 | my $remote_tasks = topic2timelog_tasks('Intranet.MinhasAtividades?template=view.text'); | ||
| 46 | concat_tasks($remote_tasks); |

