-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcron.pl
executable file
·52 lines (35 loc) · 1.18 KB
/
cron.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
sub main {
my $dbh = DBI->connect('dbi:SQLite:dbname=queue.db', '', '');
my $update = $dbh->prepare("UPDATE queue SET status = ? WHERE id = ?");
$dbh->begin_work();
my $select = $dbh->prepare("SELECT * FROM queue WHERE status = 'pending' LIMIT 1");
$select->execute();
while (my $row = $select->fetchrow_hashref) {
my $id = $row->{id};
my $url = $row->{url};
print "Marking $id as downloading\n";
$update->execute('downloading', $id);
$dbh->commit();
print "Capturing $url as $id.png\n";
my @command = (
'./screenshot.pl', $url,
'--output', "captures/$id.$row->{type}",
);
foreach my $field ( qw(size type proxy xpath pause) ) {
my $value = $row->{$field};
push @command, "--$field", $value if $value;
}
print "Running @command\n";
my $exit = system @command;
my $status = $exit == 0 ? 'done' : 'error';
print "Marking $id as $status\n";
$update->execute($status, $id);
}
$dbh->disconnect();
return 0;
}
exit main() unless caller;