forked from seveas/hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuienradar
executable file
·611 lines (549 loc) · 25.7 KB
/
buienradar
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
#!/usr/bin/python
#
# European/Dutch weather (rain and lightning) radar.
#
# This small application will display the dutch weather radar data provided by
# buienradar.nl and meteox.nl. It offers a choice between 1, 2, 3, 6, 12 and 24
# hour loops loops can be paused and navigated as well.
#
# (c)2009 Dennis Kaarsemaker <[email protected]> This is free software,
# licensed under the GNU GPL, version 3 or later.
#
# Downloaded data is (c) buienradar.nl/meteox.nl, all rights reserved.
import datetime
import logging
import math
import os
import pygtk; pygtk.require('2.0'); import gtk, glib
import sys
import urllib2
__version__ = (1,5)
import warnings
warnings.filterwarnings('ignore', 'could not open display')
from collections import namedtuple
_t = namedtuple('country',('country','bg','url','interval'))
class BuienRadar(object):
"""BuienRadar GUI, display dutch weather radar images"""
cache_dir = os.path.join(os.path.expanduser('~'), '.cache', 'buienradar')
countries = {'nl':
_t('Nederland',
'http://www.buienradar.nl/kaart1x1-550.gif',
'http://www6.buienradar.nl/images.aspx?soort=1x1&bliksem=1' + \
'&jaar=%(year)d' + \
'&maand=%(month)02d' + \
'&dag=%(day)02d' + \
'&uur=%(hour)02d' + \
'&minuut=%(minute)02d',
300),
'eu':
_t('Europe',
'http://europa.buienradar.nl/kaart.gif',
'http://www.meteox.nl/images.aspx?lightning=1' + \
'&jaar=%(year)d' + \
'&maand=%(month)02d' + \
'&dag=%(day)02d' + \
'&uur=%(hour)02d' + \
'&minuut=%(minute)02d',
900),
'de':
_t('Deutschland',
'http://www.niederschlagsradar.de/kaarten/duitsland-550x512.gif',
'http://www.niederschlagsradar.de/image.ashx?type=bild' + \
'&time=%(year)d%(month)02d%(day)02d%(hour)02d%(minute)02d',
300),
'be':
_t(u'Belgi\u00eb',
'http://buienradar.be/kaart1x1-320.gif',
#'http://www.buienradar.be/images.aspx?bliksem=1&soort=beeld1x1' +
#'&jaar=%(year)d' + \
#'&maand=%(month)02d' + \
#'&dag=%(day)02d' + \
#'&uur=%(hour)02d' + \
#'&minuut=%(minute)02d',
'http://www.buienradar.be/image/?time=%(year)d%(month)02d%(day)02d%(hour)02d%(minute)02d',
300),
'se':
_t('Sverige',
'http://www.vaderradar.se/images/scandinavie-550x512-pc.gif',
'http://www.vaderradar.se/image.ashx?' + \
'&time=%(year)d%(month)02d%(day)02d%(hour)02d%(minute)02d',
900),
'dk':
_t('Danmark',
'http://www.bygeradar.dk/images/denemarken-550x512.gif',
'http://www.bygeradar.dk/image.ashx?' + \
'&time=%(year)d%(month)02d%(day)02d%(hour)02d%(minute)02d',
900),
}
hour_choices = (1, 2, 3, 6, 12, 24)
def __init__(self, gui, country, loglevel, seconds):
"""Initialize the GUI and internal data"""
# Not playing yet
self.last_step = 0
self.playing = False
self.downloading = None
self.images = {}
# Logging
self.init_logger(loglevel)
# Which radar images?
self.set_country(country=country)
self.gui = gui
# The window
if self.gui:
self.create_gui(seconds)
self.set_seconds(seconds=seconds)
# Make sure we can store our images
if not os.path.exists(self.cache_dir):
os.makedirs(self.cache_dir)
def create_gui(self, seconds):
self.window = w = gtk.Window(gtk.WINDOW_TOPLEVEL)
w.set_title("Weather radar %s" % '.'.join(str(x) for x in __version__))
w.connect("delete_event", self.quit)
w.connect("destroy", self.quit)
w.connect("key_release_event", self.key_release)
w.set_icon(logo)
w.set_resizable(False)
vbox = gtk.VBox()
w.add(vbox)
# Menubar
mb = gtk.MenuBar()
vbox.pack_start(mb, expand=False)
fmi = gtk.MenuItem(label="Weather radar")
mb.append(fmi)
fm = gtk.Menu()
fmi.set_submenu(fm)
for country in sorted(self.countries.keys()):
it = gtk.MenuItem(self.countries[country].country)
it.connect("activate", self.set_country, country)
fm.append(it)
it = gtk.MenuItem("Clear cache")
it.connect("activate", self.clear_cache, 0)
fm.append(it)
it = gtk.ImageMenuItem(gtk.STOCK_QUIT)
it.connect("activate", self.quit)
fm.append(it)
# Player interface
hbox = gtk.HBox()
vbox.pack_start(hbox, expand=False)
self.combo_box = b = gtk.combo_box_new_text()
hbox.pack_start(b,expand=False)
active = 0
for n,i in enumerate(self.hour_choices):
b.append_text('%d hour' % i)
if i * 3600 == seconds:
active = n
b.set_active(active)
b.connect('changed', self.set_seconds)
self.playbutton = b = gtk.Button(stock=gtk.STOCK_MEDIA_PLAY)
b.set_use_stock(True)
b.connect("clicked", self.toggle_playing)
hbox.pack_start(b,expand=False)
self.scale = s = gtk.HScale()
hbox.pack_start(s)
s.set_draw_value(False)
s.set_range(0,1)
s.connect('change-value', self.adjust_slider)
s.connect('button-press-event', self.pause_playing)
s.connect('button-release-event', self.resume_playing)
self.paused = False
self.last_manual = None
# The image
self.image = gtk.Image()
vbox.pack_start(self.image)
# Statusbar
self.statusbar = sb = gtk.Statusbar()
vbox.pack_start(sb, expand=False)
sb.set_has_resize_grip(False)
self.window.set_focus(None)
def main(self):
"""Show the gui and run the mainloop. Also start the player"""
if self.gui:
self.window.show_all()
glib.idle_add(self.start_playing)
glib.timeout_add(900000, self.clear_cache, None)
gtk.main()
def quit(self, eventsrc, *args):
"""Quit the mainloop"""
gtk.main_quit()
# Player control
# start/stop and pause/resume are very similar, the difference is in what
# calls them:
# - start/stop are callbacks for the plau/pause button
# - pause/resume are called when the slider is being dragged. Animation
# will continue when the slider is let go
def start_playing(self):
"""Start the animation"""
if self.playing:
return
self.playing = True
if self.gui:
self.playbutton.set_label(gtk.STOCK_MEDIA_PAUSE)
self.timer = glib.timeout_add(self.timeout, self.play_step)
def stop_playing(self):
"""Stop the animation"""
if not self.playing:
return
glib.source_remove(self.timer)
if self.gui:
self.playbutton.set_label(gtk.STOCK_MEDIA_PLAY)
self.playing = False
def pause_playing(self, eventsrc, event):
"""Pause the animation"""
if self.playing and not self.paused:
self.stop_playing()
self.paused = True
self.window.set_focus(None)
def resume_playing(self, eventsrc, event):
"""Continue the animation"""
if self.paused and not self.playing:
if self.last_manual:
glib.source_remove(self.last_manual)
self.last_manual = None
self.start_playing()
self.paused = False
self.window.set_focus(None)
# GUI response
def toggle_playing(self, eventsrc):
"""Callback for the plau/payse button"""
if self.playing:
self.stop_playing()
else:
self.start_playing()
def adjust_slider(self, eventsrc, scrolltype, value):
"""Callback for when the slider is moved"""
if self.last_manual:
glib.source_remove(self.last_manual)
self.last_manual = None
if self.playing:
return
step = int(self.steps * (1-value))
self.last_step = step + 1
# Use a timeout so we don't update the screen to often
self.last_manual = glib.timeout_add(50, self.play_step, False)
self.window.set_focus(None)
def set_seconds(self, eventsrc=None, seconds=0):
"""Callback for the dropdown duration selector"""
if eventsrc:
t = eventsrc.get_active_text()
self.seconds = int(t.split(None,1)[0]) * 3600
else:
self.seconds = seconds
self.steps = self.seconds/self.interval
if self.last_step > self.steps:
self.last_step = self.steps
self.set_timeout(12000/self.steps)
def key_release(self, eventsrc, event):
key = gtk.gdk.keyval_name(event.keyval).lower()
if key == 'p':
self.toggle_playing(eventsrc)
elif key == 'left':
self.stop_playing()
self.last_step = (self.last_step+2) % (self.steps+1)
self.play_step()
elif key == 'right':
self.stop_playing()
self.play_step()
elif key.isdigit() and int(key) in self.hour_choices:
key = int(key)
self.set_seconds(seconds = key * 3600)
self.combo_box.set_active(self.hour_choices.index(key))
else:
last_c = '_'
for country in sorted(self.countries.keys()):
if country[0] == key:
self.set_country(country=country)
break
elif last_c == country[0] and country[1] == key:
self.set_country(country=country)
break
last_c = country[0]
# Player/display functions
def play_step(self, set_scale=True):
"""Advance the step counter and load the relevant image"""
self.logger.info("Playing step: %d/%d" % (self.last_step, self.steps))
if self.last_step == 0:
self.cycle_time = self.load_image(datetime.datetime.now())
self.last_step = self.steps
else:
self.last_step -= 1
self.load_image(self.cycle_time - datetime.timedelta(0, self.interval * self.last_step))
if self.gui:
if set_scale:
self.scale.set_value(1-(0.0+self.last_step)/self.steps)
self.window.set_focus(None)
if self.last_step == 0 and not self.gui:
self.clear_cache(None)
self.quit(None)
return self.playing
def set_timeout(self, timeout):
"""Set the time between frames and restart the player"""
self.timeout = timeout = max(100, timeout) # Timeout must be 100ms minimum
# 1001 is a magic value, it means we are downloading images. Tell the user
if self.timeout == 1001 and not self.downloading and self.gui:
self.downloading = self.statusbar.push(1, "Slowing down animation to download images")
elif self.downloading is not None:
if self.gui and hasattr(self.statusbar, 'remove_message'):
self.statusbar.remove_message(1, self.downloading)
elif self.gui and hasattr(self.statusbar, 'remove'):
self.statusbar.remove(1, self.downloading)
self.downloading = None
if self.playing:
self.stop_playing()
self.start_playing()
def clamped_timestamp(self, timestamp):
"""Returns the timestamp with second/microsecond set to 0 and minute to minute % self.interval"""
return timestamp - datetime.timedelta(0, (timestamp.minute * 60 + timestamp.second) % self.interval, timestamp.microsecond)
def load_image(self, timestamp):
"""Load the relevant image for the timestamp. Will try to download images and
will also try to download older images if the current one is not yet
available. Return value is the timestamp for the image actually loaded.
This may differ trom the timestamp argument."""
timestamp = self.clamped_timestamp(timestamp)
# Too old. Paused for too long? Restart the animation by resetting
# the step counter.
if timestamp < datetime.datetime.now() - datetime.timedelta(1,1800):
self.last_step = 0
return
# Have we cached this image in memory?
if (timestamp, self.postfix) in self.images:
# Unset the magic "We're downloading" timeout
if self.timeout == 1001 and self.last_step > 2:
self.set_timeout(12000/self.steps)
self.image.set_from_pixmap(self.images[(timestamp, self.postfix)], None)
return timestamp
imgfile = os.path.join(self.cache_dir, timestamp.strftime('%Y%m%d%H%M') + self.postfix + '.gif')
self.logger.info("Loading %s" % imgfile)
# Have we cached this image on disk?
if os.path.exists(imgfile):
# Unset the magic "We're downloading" timeout
if self.timeout == 1001 and self.last_step > 2:
self.set_timeout(12000/self.steps)
if not self.gui:
return timestamp
else:
# Set the magic "We're downloading" timeout
if self.last_step > 2 and self.timeout != 1001:
self.set_timeout(1001)
url = self.url % {'year': timestamp.year,
'month': timestamp.month,
'day': timestamp.day,
'hour': timestamp.hour,
'minute': timestamp.minute}
self.logger.debug("Downloading %s" % url)
try:
req = urllib2.urlopen(url)
except urllib2.URLError as e:
if e.code == 404:
self.logger.debug("Download failed for %s" % url)
return self.load_image(timestamp - datetime.timedelta(0, self.interval))
# Failed to download image
self.stop_playing()
error_dlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK,
parent=self.window,
message_format="Failed to download image. Check your internet connection and proxy settings")
error_dlg.run()
error_dlg.destroy()
sys.exit(1)
img = req.read()
if len(img) < 1000:
# Image does not exist yet, try a 5 minute older one
self.logger.debug("Download failed for %s" % url)
return self.load_image(timestamp - datetime.timedelta(0, self.interval))
# Cache the image
fd = open(imgfile, 'w')
fd.write(img)
fd.close()
if not self.gui:
return timestamp
# Load the cached image from disk
try:
pb = gtk.gdk.pixbuf_new_from_file(imgfile)
pb.saturate_and_pixelate(pb, self.saturation(timestamp), False)
pm = gtk.gdk.Pixmap(None, pb.get_property('width'), pb.get_property('height'), 24)
if self.background:
bg = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.background.get_property('width'), self.background.get_property('height'))
self.background.saturate_and_pixelate(bg, self.saturation(timestamp), False)
pb.add_alpha(False, 0, 0, 0)
pb.composite(bg, 0, 0, pb.get_property('width'), pb.get_property('height'), 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 192)
pm.draw_pixbuf(None,bg,0,0,0,0)
else:
pm.draw_pixbuf(None,pb,0,0,0,0)
self.images[(timestamp, self.postfix)] = pm
except glib.GError:
self.logger.warning("Unable to load %s, re-downloading" % imgfile)
os.unlink(imgfile)
return self.load_image(timestamp)
self.image.set_from_pixmap(self.images[(timestamp, self.postfix)], None)
return timestamp
def load_background(self, bg):
if bg is None:
return None
if ('bg', self.postfix) not in self.images:
imgfile = os.path.join(self.cache_dir, 'bg' + self.postfix + '.gif')
self.logger.info("Loading %s" % imgfile)
if not os.path.exists(imgfile):
url = bg
self.logger.debug("Downloading %s" % url)
try:
req = urllib2.urlopen(url)
except urllib2.URLError:
# Failed to download image
self.stop_playing()
error_dlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK,
parent=self.window,
message_format="Failed to download image. Check your internet connection and proxy settings")
error_dlg.run()
error_dlg.destroy()
return
img = req.read()
# Cache the image
fd = open(imgfile, 'w')
fd.write(img)
fd.close()
# Load the cached image from disk
try:
pb = gtk.gdk.pixbuf_new_from_file(imgfile)
self.images[('bg', self.postfix)] = pb
except glib.GError:
self.logger.warning("Unable to load %s, re-downloading" % imgfile)
os.unlink(imgfile)
return self.load_background(bg)
return self.images[('bg', self.postfix)]
# Other functions
def init_logger(self, level):
self.logger = l = logging.getLogger("buienradar")
l.setLevel(level=level)
c = logging.StreamHandler()
c.setLevel(level=level)
c.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
l.addHandler(c)
def set_country(self, eventsrc=None, country='eu'):
old_url = getattr(self, 'url', None)
self.url = self.countries[country].url
self.postfix = '_' + country
self.background = self.load_background(self.countries[country].bg)
self.interval = self.countries[country].interval
if hasattr(self, 'seconds'):
self.steps = self.seconds/self.interval
self.set_timeout(12000/self.steps)
if old_url != self.url and old_url != None and not self.playing:
self.play_step()
saturation_factor = 0.25
saturation_base = 1 - saturation_factor
saturation_offset = 1.0 / 12
def saturation(self, timestamp):
"""Return the saturation for the time, making images darker or not.
Currently this is a naive cosine with a 2h offset making 02:00
the darkest and 14:00 the lightest"""
ts = (timestamp.hour * 60.0 + timestamp.minute) / 1440.0 - self.saturation_offset
sat = self.saturation_base - self.saturation_factor * math.cos(ts * 2.0 * math.pi)
self.logger.debug("Saturation for %s: %f" % (timestamp.strftime("%H:%M"), sat))
return sat
def clear_cache(self, eventsrc, age=87300):
"""Remove all downloaded image files and clean the memory cache"""
max_age = datetime.datetime.now() - datetime.timedelta(0, age)
max_age_str = max_age.strftime('%Y%m%d%H%M')
for f in os.listdir(self.cache_dir):
if f < max_age_str:
self.logger.info("Deleting %s" % f)
os.unlink(os.path.join(self.cache_dir, f))
for k in self.images.keys():
if k[0] < max_age:
self.logger.debug("Forgetting %s image for %s" % (k[1], k[0].strftime("%Y-%m-%d %H:%M")))
del self.images[k]
# This is called from a timeout_add, so return True to keep the
# loop alive.
return True
# http://www.buienradar.nl/favicon.ico converted to xpm with imagemagick
# $ wget -O- http://www.buienradar.nl/favicon.ico
# $ convert -format xpm favicon.ico favicon.xpm
# $ cat favicon.xpm
logo = gtk.gdk.pixbuf_new_from_xpm_data([
"16 16 181 2",
" c #3163AD", ". c #3264AD", "X c #3364AD", "o c #3365AD", "O c #3365AE",
"+ c #3465AD", "@ c #3466AD", "# c #3567AD", "$ c #3465AE", "% c #3466AE",
"& c #3566AE", "* c #3667AF", "= c #3768AE", "- c #396BAD", "; c #3869AE",
": c #3A6CAD", "> c #3D6EAF", ", c #386AB0", "< c #3B6DB0", "1 c #3C6CB0",
"2 c #3C6CB1", "3 c #3D6CB1", "4 c #3F6DB0", "5 c #406FB3", "6 c #4070B0",
"7 c #4171B0", "8 c #4271B1", "9 c #4170B3", "0 c #4370B3", "q c #4471B3",
"w c #4772B6", "e c #4B77B5", "r c #4C77B5", "t c #4A78B4", "y c #4B79B4",
"u c #4B79B5", "i c #4C7AB6", "p c #4E7BB6", "a c #4F7BB6", "s c #4F7AB7",
"d c #4D7AB9", "f c #507BB9", "g c #527EB9", "h c #517DBA", "j c #547FBA",
"k c #5D84BC", "l c #5F85BD", "z c #5F87BD", "x c #5D86BF", "c c #6089BF",
"v c #658DC0", "b c #678DC0", "n c #688DC3", "m c #6991C6", "M c #7297C7",
"N c #799AC7", "B c #7C9BC7", "V c #7B9BC8", "C c #7A9CC9", "Z c #7A9CCB",
"A c #7C9EC9", "S c #7C9DCC", "D c #7F9ECD", "F c #7DA5D6", "G c #7EA7D7",
"H c #80A2CB", "J c #81A0CC", "K c #84A4CD", "L c #87A5CD", "P c #89A6CF",
"I c #8EADCF", "U c #82A5D6", "Y c #83A6D6", "T c #8CA6D2", "R c #83A8D7",
"E c #87A8D7", "W c #81A7D8", "Q c #85ABD8", "! c #89AAD9", "~ c #8AABD9",
"^ c #8AADD8", "/ c #8BADDD", "( c #91ABD2", ") c #90ADDA", "_ c #89B0D8",
"` c #8DB0D9", "' c #94B3D5", "] c #98B3D6", "[ c #91B5DB", "{ c #92B1DC",
"} c #97B5DC", "| c #95B5DE", " . c #9BB6DA", ".. c #9CB5D8", "X. c #9AB8DE",
"o. c #9DB9DE", "O. c #A0B7D8", "+. c #A4BDD9", "@. c #A2BDDF", "#. c #A3BDDF",
"$. c #A5BCDC", "%. c #98B4E0", "&. c #A2BBE1", "*. c #AAC2DD", "=. c #A3C1E0",
"-. c #A8C1E1", ";. c #AAC0E0", ":. c #ADC2E0", ">. c #AEC6E3", ",. c #A9C3E5",
"<. c #B4C6E1", "1. c #B2C6E5", "2. c #B4C7E5", "3. c #B5C9E5", "4. c #B5C8E6",
"5. c #B5CBE7", "6. c #B9CCE5", "7. c #BACDE5", "8. c #B8CEE6", "9. c #BCCFE6",
"0. c #BDCFE7", "q. c #BECFE8", "w. c #BDCFEB", "e. c #BBD0EB", "r. c #BDD1E9",
"t. c #BED2E9", "y. c #BED1EA", "u. c #C2D1E7", "i. c #C0D2E7", "p. c #C3D2EA",
"a. c #C3D6EB", "s. c #C7D6E9", "d. c #C6D4EA", "f. c #C6D5EC", "g. c #C5D4EE",
"h. c #C9D7EE", "j. c #CCD7EC", "k. c #CAD8EB", "l. c #CCD8EB", "z. c #CCDAED",
"x. c #CED9EF", "c. c #CFDAEE", "v. c #CEDCEC", "b. c #CEDDED", "n. c #D1DBEE",
"m. c #D0DBEF", "M. c #D1DDEE", "N. c #D3DDEF", "B. c #D0DEEE", "V. c #D2DEEF",
"C. c #CCDAF0", "Z. c #D2DFF1", "A. c #D3DEF2", "S. c #D4DEF0", "D. c #D6E3F2",
"F. c #D9E2F3", "G. c #DBE2F2", "H. c #DCE2F0", "J. c #DAE7F1", "K. c #D9E6F3",
"L. c #DAE6F3", "P. c #D9E2F4", "I. c #E0E6F3", "U. c #E4EEF5", "Y. c #E5EDF7",
"T. c #EBEFF7", "R. c #EEEFF7", "E. c #E0EDF8", "W. c #E6F0F5", "Q. c #EBF4F7",
"!. c #EDF5F7", "~. c #EFF2FB", "^. c #F5F5FA", "/. c #F6F6FA", "(. c #F3F9F9",
"). c #F4F9F9", "_. c #F9F9FF", "`. c #FBFCFE", "'. c #FDFDFE", "]. c #FCFEFE",
"[. c gray100",
"[.[.[.[.[.[.^.T.T./.[.[.[.[.'.R.",
"[.[.[.(.9.H k e r l K i.).`.Y.C.",
"[.[.I.B p 7 ; X o & d .~.S.e.Q.",
"[.I.b 8 # o . @ g ..P.g.1.W.].",
"(.J 2 o . x :.Z.8.*.G.E._.",
"9.u O , m 3.m.>.=.z.c.D p.",
"A > . 4 Z 0.l.;.o.a.n.S 0 K ",
"y : . 4 L u.f.#.} y.v.T 5 & l ",
"- # . s ( k.t.X.{ 5.b.] w $ f ",
"- # h O.N.r.[ ^ 2.M.+.j $ f ",
"i c $.A.4.` Q -.V.<.z @ & k ",
"' 7.F.,.~ W &.B.6.n @ 1 H ",
"[email protected] U %.x.s.M @ + a q.",
"D.| G U ) h.j.C < . 3 V _.",
"/ Y F ! d.H.P 9 @ 6 v K.[.",
"_ G E w.U.I t = $ % * q N L.[.[."
])
if __name__ == '__main__':
from optparse import OptionParser, OptionConflictError
parser = OptionParser()
parser.add_option('-v', '--verbose', action='count', dest='verbosity',
help="Verbose output (use twice for higher verbosity)")
parser.add_option('--no-gui', action='store_false', dest='gui', default=True,
help="Don't show a GUI, just download images")
for h, s in [(str(x), x * 3600) for x in BuienRadar.hour_choices]:
if len(h) == 1:
parser.add_option('-' + h, '--' + h, dest='seconds', default=10800,
action='store_const', const=s,
help="Show a %s hour loop" % h)
else:
parser.add_option('--' + h, dest='seconds', default=10800,
action='store_const', const=s,
help="Show a %s hour loop" % h)
for c in sorted(BuienRadar.countries.keys()):
try:
parser.add_option('-' + c[0], '--' + c, dest='country', default='eu',
action='store_const', const=c,
help=BuienRadar.countries[c].country)
except OptionConflictError:
parser.add_option('-' + c[1], '--' + c, dest='country', default='eu',
action='store_const', const=c,
help=BuienRadar.countries[c].country)
options, args = parser.parse_args()
if args:
parser.print_help()
sys.exit(1)
level = {1: logging.INFO, 2: logging.DEBUG}.get(options.verbosity, logging.WARNING)
BuienRadar(options.gui, options.country, level, options.seconds).main()
# `Now you see it,' said the bird. `Now you don't.'
# - Douglas Adams, Mostly Harmless