forked from davetroy/votereport
/
cachefiles
executable file
·69 lines (61 loc) · 1.78 KB
/
cachefiles
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
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use File::Copy;
my $pid = fork();
exit 0 if ($pid != 0);
my @abbr = ("AL","AK","AS","AZ","AR","CA","CO","CT","DE","DC","FM","FL","GA","GU","HI","ID","IL","IN","IA","KS","KY","LA","ME","MH","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","MP","OH","OK","OR","PW","PA","PR","RI","SC","SD","TN","TX","UT","VT","VI","VA","WA","WV","WI","WY");
my $ua = LWP::UserAgent->new;
while (1)
{
#print "Beginning fetching run.\n";
my $res = $ua->get("http://votereport.us/reports.kml?live=1&count=4000");
my $content = $res->content;
open(KML, ">reports.kml");
print KML $content;
close(KML);
move("reports.kml", "public/feeds/4000.kml");
$res = $ua->get("http://votereport.us/reports.atom");
$content = $res->content;
open(ATOM, ">reports.atom");
print ATOM $content;
close(ATOM);
move("reports.atom", "public/feeds/reports.atom");
#print "KML and Atom fetched.\n";
for (my $i=0;$i<scalar @abbr;$i++)
{
state($abbr[$i],$ua);
}
#print "States fetched.\n";
homepage($ua);
#print "Homepages fetched.\n";
#print "Ending fetching run. Now going to sleep.\n";
sleep(60);
}
sub state
{
my $state = shift;
my $ua = shift;
for (my $i=1;$i<=3;$i++)
{
open (STATE, ">$i.json");
my $res = $ua->get("http://votereport.us/reports.json?state=$state&wait_time=0&per_page=200&callback=updateJSON&page=$i");
print STATE $res->content;
close STATE;
move("$i.json", "public/feeds/json/$state/$i.json");
}
}
sub homepage
{
my $ua = shift;
for (my $i=1;$i<=20;$i++)
{
my $res = $ua->get("http://votereport.us/reports.json?wait_time=0&per_page=200&callback=updateJSON&page=$i");
my $content = $res->content;
open(JSON, ">$i.json");
print JSON $content;
close(JSON);
move("$i.json", "public/feeds/$i.json");
}
}