-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNEO.pl
74 lines (74 loc) · 1.89 KB
/
NEO.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/local/bin/perl
use strict; use warnings; $|=1; $0='NEO';
use File::Find::Rule;
use WWW::Mechanize;
use Proc::Daemon;
use LWP::UserAgent;
use LWP::Protocols::https;
################### SUMMONS #
# NEO - scrape searchcode.com
# (<>..<>) ---skry of MKRX
# SETUP ###############################
my $work = 'MINION/' my $dump = 'dump';
my $state = 'STATE'; my $debug = 'DEBUG';
my $log = 'LOG'; my $pid = 'PID';
my $que = 'QUE'; my $clean = 'CLEAN'
my $pause = 'PAUSE'; my $shutdown = 'SHUT';
# DAEMONIZE ##########################
my $daemon = Proc::Daemon->new(
work_dir => $work,
child_STDOUT => $log,
child_STDERR => +>>$debug,
pid_file => $pid,
);
$daemon->Init();
# USER AGENT ###############
my $ua = uagent();
# PROC ###################
open(my $ifh, '<', $init) or die "Couldn't read $init\n";
my $point = readline $ifh; chomp $point; close $ifh;
while ($point < 127100000) {
sleep 1;
if (-e "NEO_SHUTDOWN")
{ shut(); }
if (-e "NEO_PAUSE")
{ pause(); }
$point++;
print "$point started\n";
my $url = "$base$point";
my $mech = WWW::Mechanize->new();
if (eval {$mech->get($url)}) {
$mech->save_content("$dump/$point");
print "$point ended\n";
}
else
{ print "$point fail\n"; next; }
# ACCOUNTING ###############
if ($point % 100 == 0) {
open(my $fifh, '<', $init) or die "Couldn't read $init\n";
print $fifh "$point\n"; close $fifh;
}
}
# SUB ######################
sub pause {
my $pausefile = "NEO_PAUSE";
open(my $pfh, '<', $pausefile) or die "no $pausefile";
my $timeout = readline $pfh; chomp $timeout;
print "sleeping for $timeout\n"; sleep $timeout;
}
sub shut {
my $shut = "NEO_SHUTDOWN";
unlink $shut;
open(my $sinitfh, '>', $init);
foreach (@list)
{ print $sinitfh "$_\n"; }
die "Shutdown CLEAN";
}
sub uagent {
my $s_ua = LWP::UserAgent->new(
agent => "Mozilla/50.0.2",
from => '[email protected]',
timeout => 45,
);
return $s_ua;
}