summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2012-01-16 18:28:52 +0100
committerChristian Franke <nobody@nowhere.ws>2012-01-16 18:30:28 +0100
commit9f9d7489b5b6b34f4be3ef57ae644b96aa3d7e4b (patch)
tree630a7cf141b08979cf688fee6baae309ededf88c
parent94e8ad7c38f3a2efd78e81a2ad74995944a82a8e (diff)
Add tasks which fetch webcam images
-rw-r--r--sublab_project/fixtures/flatpages.json2
-rw-r--r--sublab_project/sublab_monitor/tasks.py69
-rw-r--r--sublab_project/templates/base.html9
3 files changed, 76 insertions, 4 deletions
diff --git a/sublab_project/fixtures/flatpages.json b/sublab_project/fixtures/flatpages.json
index 09077dd..9fa5991 100644
--- a/sublab_project/fixtures/flatpages.json
+++ b/sublab_project/fixtures/flatpages.json
@@ -115,7 +115,7 @@
"sites": [
1
],
- "content": "<h2>Webcams</h2>\r\n<p>\r\n\tIm sublab befinden sich mehrere Webcams.\r\n\tDie Aufnahmen einiger Webcams werden hier zur Verf\u00fcgung gestellt.\r\n</p>\r\n<h3>\r\n\tPeriskop\r\n</h3>\r\n<div class=\"imagecontent\">\r\n\t<a href=\"img/rack.webcam.jpg\" target=\"_blank\" class=\"img\"><img src=\"img/rack.webcam.jpg\" alt=\"Karl-Heine-Strasse\" class=\"contentimage\"></a>\r\n</div>\r\n<p>\r\n\tDiese Webcam zeigt den Blick nach Westen aus unseren Fenstern, entlang der Karl-Heine-Stra\u00dfe. Linker Hand befindet sich die GaraGe, im Vordergrund die Villa (auf dem Westwerkgel\u00e4nde), und rechter Hand das Jahrtausendfeld.<br> \r\n\tIm Hintergrund befindet sich die Baustelle des Taschenkaufhauses.\r\n</p>\r\n<h3>\r\n\tDachcam\r\n</h3>\r\n<div class=\"imagecontent\">\r\n\t<a href=\"img/dach.webcam.jpg\" target=\"_blank\" class=\"img\"><img src=\"img/dach.webcam.jpg\" alt=\"Dachcam\" class=\"contentimage\"></a>\r\n</div>\r\n<p>\r\n\tAuf dieser Webcam ist ein Blick nach Osten ueber das angrenzende Dach der gro\u00dfen Halle des Westwerks zu sehen.\r\n</p>\r\n",
+ "content": "<h2>Webcams</h2>\r\n<p>\r\n\tIm sublab befinden sich mehrere Webcams.\r\n\tDie Aufnahmen einiger Webcams werden hier zur Verf\u00fcgung gestellt.\r\n</p>\r\n<h3>\r\n\tPeriskop\r\n</h3>\r\n<div class=\"imagecontent\">\r\n\t<a href=\"/media/karlheine_cam.jpg\" target=\"_blank\" class=\"img\"><img src=\"/media/karlheine_cam.jpg\" alt=\"Karl-Heine-Strasse\" class=\"contentimage\"></a>\r\n</div>\r\n<p>\r\n\tDiese Webcam zeigt den Blick nach Westen aus unseren Fenstern, entlang der Karl-Heine-Stra\u00dfe. Linker Hand befindet sich die GaraGe, im Vordergrund die Villa (auf dem Westwerkgel\u00e4nde), und rechter Hand das Jahrtausendfeld.<br> \r\n\tIm Hintergrund befindet sich die Baustelle des Taschenkaufhauses.\r\n</p>",
"enable_comments": false
}
}
diff --git a/sublab_project/sublab_monitor/tasks.py b/sublab_project/sublab_monitor/tasks.py
index 33dcad6..20f8ad8 100644
--- a/sublab_project/sublab_monitor/tasks.py
+++ b/sublab_project/sublab_monitor/tasks.py
@@ -3,6 +3,11 @@
from datetime import timedelta
from celery.task import PeriodicTask
import subprocess
+import urllib2
+from PIL import Image, ImageOps
+from StringIO import StringIO
+from django.conf import settings
+import os
import sublab_monitor
@@ -14,7 +19,7 @@ class NetworkStatus(PeriodicTask):
'trieste': '172.22.80.4',
'nautilus': '172.22.80.7',
}
- run_every = timedelta(minutes=4)
+ run_every = timedelta(minutes=2)
ignore_result = True
def __init__(self, *args, **kwargs):
@@ -44,3 +49,65 @@ class NetworkStatus(PeriodicTask):
storage.set(host, status)
return repr(results)
+
+
+class ImageFetcher(object):
+ """
+ A task mixin which downloads, processes and stores an Image
+ """
+
+ @property
+ def fetch_url(self):
+ """
+ The location from which the image should be fetched
+ """
+ raise NotImplementedError
+
+ @property
+ def store_name(self):
+ """
+ The name under which the image should be stored
+ """
+ raise NotImplementedError
+
+ def process_image(self, image):
+ """
+ This method may be overwritten to perform some
+ processing on the image
+ """
+ raise NotImplementedError
+
+ def run(self, **kwargs):
+ upstream = urllib2.urlopen(self.fetch_url).read()
+ image = Image.open(StringIO(upstream))
+
+ try:
+ image = self.process_image(image)
+ except NotImplementedError:
+ pass
+
+ fn = os.path.join(settings.MEDIA_ROOT, self.store_name)
+ fn_new = os.path.join(settings.MEDIA_ROOT, 'new-%s' % self.store_name)
+
+ image.save(fn_new)
+ os.rename(fn_new, fn)
+
+
+class EnhancingImageFetcher(ImageFetcher):
+ def process_image(self, image):
+ rv = ImageOps.autocontrast(image)
+ rv.im = ImageOps.unsharp_mask(rv, 10.0, 40, 7)
+
+ return rv
+
+
+class KarlHeineCamFetcher(EnhancingImageFetcher, PeriodicTask):
+ run_every = timedelta(minutes=5)
+ fetch_url = 'http://taifun.local.sublab.org/webcam.jpg'
+ store_name = 'karlheine_cam.jpg'
+
+
+class TempGraphFetcher(ImageFetcher, PeriodicTask):
+ run_every = timedelta(minutes=5)
+ fetch_url = 'http://taifun.local.sublab.org/temperature/temp-2hour.png'
+ store_name = 'tempgraph.png'
diff --git a/sublab_project/templates/base.html b/sublab_project/templates/base.html
index 8dc99b0..1f9346a 100644
--- a/sublab_project/templates/base.html
+++ b/sublab_project/templates/base.html
@@ -1,5 +1,6 @@
{% load host_status %}
{% load flatblock_tags %}
+{% load thumbnail %}
<!DOCTYPE HTML>
<html>
<head>
@@ -106,9 +107,13 @@
{% flatblock "motd" %}
</p>
<hr>
- <a href="/webcam/" class="img"><img src="{{ STATIC_URL }}img/thumb.rack.webcam.jpg" alt="Webcam im Fenster" class="webcamthumb"></a>
+ {% thumbnail "karlheine_cam.jpg" "200" upscale=False as image %}
+ <a href="/webcam/" class="img"><img src="{{ image.url }}" alt="Webcam im Fenster" class="webcamthumb"></a>
+ {% endthumbnail %}
<hr>
- <a href="{{ STATIC_URL }}img/tempgraph.png" class="img"><img src="img/thumb.tempgraph.png" alt="Temperaturen im sublab" class="webcamthumb"></a>
+ {% thumbnail "tempgraph.png" "200" upscale=False as image %}
+ <a href="{{ MEDIA_URL }}tempgraph.png" class="img"><img src="{{ image.url }}" alt="Temperaturen im sublab" class="webcamthumb"></a>
+ {% endthumbnail %}
<hr>
<p class="member">
<a href="{{ STATIC_URL }}pdf/sublab_ev_mitgliedsantrag.pdf">Mitglied werden</a>