forked from tchernicum/bcapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc-contourplot.pl
executable file
·47 lines (31 loc) · 1.12 KB
/
bc-contourplot.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
#!/bin/perl
# Uses Mathematica's "contourplot" function to display temperatures,
# not voronoi
push(@INC,"/usr/local/lib");
require "bclib.pl";
# below copied from bc-generic-voronoi
open(A,"egrep '^KNM' db/wstations.txt|");
while (<A>) {
chomp;
# ok, if it's less than five minutes old...
if (-f ("/tmp/pws-$_.xml") && (-M ("/tmp/pws-$_.xml") < 300/86400)) {next;}
# TODO: hardcoding filenames here is bad, but can't use
# cache_command, since I'm using parallel
push(@cmd, "curl -s -o /tmp/pws-$_.xml 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=$_'");
}
close(A);
write_file(join("\n",@cmd)."\n", "/tmp/pws-suck.sh");
system("parallel < /tmp/pws-suck.sh");
print "temps={\n";
for $i (glob("/tmp/pws-*.xml")) {
$data = read_file($i);
# fill hash with data
$hashref = {};
while ($data=~s%<(.*?)>(.*?)</\1>%%) {$$hashref{$1}=$2};
# ignore those sans station_id
unless ($$hashref{station_id}) {next;}
# ignore temps over 139F
if ($$hashref{temp_f} > 139) {next;}
print "{$$hashref{longitude}, $$hashref{latitude}, $$hashref{temp_f}},\n";
}
print "}\ntemps=Drop[temps,-1];\n";