App-Automaton
view release on metacpan or search on metacpan
lib/App/Automaton.pm view on Meta::CPAN
$self->logger("Removing duplicates");
@hash{@{$self->{found_bits}}} = ();
@{$self->{found_bits}} = keys %hash;
return 1;
}
sub logger {
my $self = shift;
my $message = shift;
if ($self->{debug}) {
print STDERR "$message\n";
}
return 1;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::Automaton - Execute various tasks based on input from various sources
=head1 VERSION
version 0.150912
=head1 SYNOPSIS
my $a = App::Automaton->new(conf_file => $conf_file);
$a->check_sources();
$a->apply_filters();
$a->dedupe();
$a->do_actions();
or just use the shell utility:
automaton
=head1 DESCRIPTION
This project is an attempt to realize the tiniest bit of my desire to have my computer automatically execute tasks for me.
The not so ambitious first step is to receive URLs from various sources and download them for me.
The core concepts are as follows:
Automaton is designed to run periodically from Cron or something similar. Although, there is no reason you couldn't just run it manually.
It will gather input from it's input plugins, pass it through any specified filter plugins, and pass it on to it's action plugins.
The action plugins will parse each line of the input and execute any appropriate actions. The input will then be passed on to the next action plugin.
The following plugins are available now with the initial release:
* Input
* File: Reads all lines from a file and adds them to it's queue to be processed
* IMAP: Reads all messages from an IMAP email account and adds the content of each message to the queue
* Filter
* Unshorten: Looks for URLs from several known URL shortener services and expands them to full URLs
* Action
* YouTube: Downloads the video from a YouTube.com url
* TedTalks: Downloads the video from a TedTalks.com url
* NZB: Downloads the NZB file specified in the url
As you can see, these are all geared towards downloading videos. It's the first real world use case that I felt I could really do well.
The plugins can be appear multiple times in a config file, or left out completely. This allows you to download YouTube videos to multiple locations, for instance.
In the future, I picture giving it input that could tell it to do more interesting things. However, as long as commands are coming in over email, I'll leave the security implications minimal.
Obviously, you don't have to use that plugin. If you do, I certainly suggest not using your primary email since the password must be in the config file.
=head1 INSTALLATION
If you are working directly from source, this module can be installed using the Dist::Zilla tools:
sudo dzil install
=head1 CONFIGURATION
Once installed, you will have to create a configuration file for Automaton to operate on. Here is a sample config file that uses all of the currently available plugins.
sources:
automaton email:
bypass: 1
type: IMAP
server: imap.gmail.com
port: 993
account: notyourprimary@emailaccount.com
password: 123456
ssl: yes
delete: 0
file1:
type: File
path: ../input.txt
delete: 0
empty: 1
filters:
unshorten:
type: Unshorten
actions:
YouTube1:
bypass: 0
type: YouTube
target: ../down
NZB1:
bypass: 0
type: NZB
target: ../down
Ted1:
bypass: 0
type: TedTalks
target: ../down
You'll see there that the plugin configs are divided into sections for "input", "filters", and "actions".
Within those sections are named references to the plugin. These names allow you to have the same plugin appear multiple times, but have no other significance. They can whatever you want, but must be unique within their section.
The config that appears within the named section is passed on to that plugin during execution and allows you to specify any settings that it understands.
Here is a commented example of an IMAP plugin:
automaton email: # name, can be anything unique within it's section
( run in 2.913 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )