forked from tchernicum/bcapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbc-bg.pl
executable file
·216 lines (174 loc) · 5.98 KB
/
bc-bg.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/perl
# print updated text as my background image
# came from a hideously much longer program
# probably only useful to me <h>but I like spamming github</h>
require "/home/barrycarter/BCGIT/bclib.pl";
# need current time
$now=time();
chdir(tmpdir());
# shade of blue I want to use
$blue = "128,128,255";
# no X server? die instantly (really only useful for massive rebooting
# and errors early May 2007)
if (system("xset q 1> /dev/null 2> /dev/null")) {exit(0);}
# HACK: leave n top lines blank for apps that "nest" there
# push(@info,"","","");
# last line indicates break between blank and data
push(@err,"","");
push(@info,"______________________");
# uptime (just the seconds)
$uptime = read_file("/proc/uptime");
$uptime=~s/ .*$//;
$uptime = convert_time($uptime, "%dd%Hh%Mm");
debug("UPTIME: $uptime");
# TODO: add locking so program doesn't run twice
# TODO: add alarms (maybe)
# This is REALLY REALLY REALLY ugly <h>also, it's ugly</h>
# <h>Did I mention it's ugly?</h>
# what event occurs next?
# TODO: add time of when this event occurs to display?
$nextev = sqlite3val("SELECT event FROM abqastro WHERE time >
DATETIME('now','localtime') AND event NOT IN ('MR','MS', 'Last Quarter', 'First Quarter', 'New Moon', 'Full Moon') ORDER BY time
LIMIT 1", "/home/barrycarter/BCGIT/db/abqastro.db");
debug("NEXTEV: $nextev");
# map event to time of day
%map = (
"ATS" => "night",
"NTS" => "astronomical twilight",
"CTS" => "nautical twilight",
"SR" => "civil twilight",
"SS" => "daytime",
"CTE" => "civil twilight",
"NTE" => "nautical twilight",
"ATE" => "astronomical twilight"
);
push(@info, uc($map{$nextev}));
push(@info, "UPTIME: $uptime");
# @info = stuff we print (to top left corner)
# local and GMT time
# push(@info,strftime("MT: %Y%m%d.%H%M%S",localtime($now)));
# push(@info,strftime("GMT: %Y%m%d.%H%M%S",gmtime($now)));
# figure out what alerts to suppress
# format of suppress.txt:
# xyz stardate [suppress alert xyz until stardate (local time)]
@suppress = `egrep -v '^#' /home/barrycarter/ERR/suppress.txt`;
# know which alerts to suppress
for $i (@suppress) {
($key,$val) = split(/\s+/,$i);
# if date has already occurred, ignore line
if ($val < stardate($now,"localtime=1")) {next;}
debug("KV: $key/$val");
$suppress{$key}=$val;
}
debug("SUPPRESS",%suppress);
# all errors are in ERR subdir (and info alerts are there too)
for $i (glob("/home/barrycarter/ERR/*.err")) {
for $j (split("\n",read_file($i))) {
# unless suppressed, push to @err
if ($suppress{$j}) {next;}
push(@err,$j);
}
}
# informational messages (redundant code, sigh!)
for $i (glob("/home/barrycarter/ERR/*.inf")) {
for $j (split("\n",read_file($i))) {
# unless suppressed, push to @info
if ($suppress{$j}) {next;}
push(@info,$j);
}
}
# local weather (below info, above TZ = not great)
($out, $err, $res) = cache_command("curl -s 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KNMALBUQ80'", "age=120");
# create hash + strip trailing .0
while ($out=~s%<(.*?)>([^<>]*?)</\1>%%is) {
($key, $val) = ($1, $2);
$val=~s/\.0$//;
$hash{$key}=$val;
}
$hash{observation_time}=~s/^last updated on //isg;
push(@info, "Local/$hash{temp_f}F/$hash{wind_dir}$hash{wind_mph}G$hash{wind_gust_mph}/$hash{relative_humidity}% ($hash{dewpoint_f}F) [$hash{observation_time}]");
debug("HASH",%hash);
# I have no cronjob for world time, so...
# hash of how I want to see the zones
# explicitly excluding the Kiritimati cheat
%zones = (
"MT" => "US/Mountain",
"CT" => "US/Central",
"ET" => "US/Eastern",
"PT" => "US/Pacific",
"GMT" => "GMT",
"Lagos" => "Africa/Lagos",
"Cairo" => "Africa/Cairo",
"HongKong" => "Asia/Hong_Kong",
"Tokyo" => "Asia/Tokyo",
"Delhi" => "Asia/Kolkata",
"Sydney" => "Australia/Sydney",
"Samoa" => "Pacific/Apia",
"Pago Pago" => "Pacific/Pago_Pago"
);
# HACK: manual sorting is cheating/dangerous ... should be able to do
# this auto somehow (eg, by deviation from GMT?)
@zones= ("Pago Pago", "PT", "MT", "CT", "ET", "GMT", "Lagos", "Cairo", "Delhi",
"HongKong", "Tokyo", "Sydney", "Samoa");
for $i (@zones) {
$ENV{TZ} = $zones{$i};
push(@info, strftime("$i: %H%M,%a%d%b",localtime(time())));
}
# random (but predictable) word from BCGIT/WWF/enable-random.txt
# 172820 is fixed
$num = ($now/60)%172820;
debug("NUM: $num");
$res = `head -$num /home/barrycarter/BCGIT/WWF/enable-random.txt | tail -1`;
chomp($res);
push(@info, "WOTM: $res");
# push output to .fly script
# err gets pushed first (and in red), then info
for $i (@err) {
# TODO: order these better
push(@rss, "$i");
push(@fly, "string 255,0,0,0,$pos,giant,$i");
$pos+=15;
}
# now info (in blue for now); note $pos is "global"
for $i (@info) {
# TODO: order these better
push(@rss, "$i");
push(@fly, "string $blue,0,$pos,medium,$i");
$pos+=15;
}
# puts the International Phonetic Alphabet at the bottom right corner
# of the screen (as I am trying to learn it); technique should be
# general enough to work with any file
open(A,"tac /home/barrycarter/BCGIT/db/ipa.txt|");
$br = 768-20; # bottom y value
while (<A>) {
chomp;
$br -= 15;
# this is left justified, which means it won't work for arb files, sigh
$xval = 950;
push(@fly, "string $blue,$xval,$br,medium,$_");
debug("CHOMP: $_");
}
# create RSS (not working, will probably dump)
open(A, ">/var/tmp/bc-bg.rss");
print A qq%<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="0.91">
<channel><title>bc-bg</title><item><title>\n%;
print A join("<br>\n", @rss),"\n";
print A "</title></item></channel></rss>\n";
close(A);
# send header and output to fly file
# tried doing this w/ pipe but failed
# setpixel below needed so bg color is black
# the gray x near middle of screen is so I know a black window isn't covering root
open(A, "> bg.fly");
print A << "MARK";
new
size 1024,768
setpixel 0,0,0,0,0
setpixel 512,384,255,255,255
MARK
;
for $i (@fly) {print A "$i\n";}
close(A);
# also copy file since I will need it on other machines
system("fly -q -i bg.fly -o bg.gif; xv +noresetroot -root -quit bg.gif; cp bg.gif /tmp/bgimage.gif");