summaryrefslogtreecommitdiff
path: root/sublab_project
diff options
context:
space:
mode:
Diffstat (limited to 'sublab_project')
-rw-r--r--sublab_project/matekarte/tasks.py10
-rw-r--r--sublab_project/sublab_monitor/tasks.py33
-rw-r--r--sublab_project/templates/base.html5
3 files changed, 37 insertions, 11 deletions
diff --git a/sublab_project/matekarte/tasks.py b/sublab_project/matekarte/tasks.py
index bc1018b..5ba8fbd 100644
--- a/sublab_project/matekarte/tasks.py
+++ b/sublab_project/matekarte/tasks.py
@@ -42,8 +42,8 @@ class OSMFetcher(object):
os.rename(fn_new, fn)
-#class MateFetcher(OSMFetcher, PeriodicTask):
-# run_every = crontab(minute=0, hour=3)
-# bbox = (55.26, 46.52, 15.26, 5.22)
-# store_name = 'mate.xml'
-# tag = 'drink:club-mate'
+class MateFetcher(OSMFetcher, PeriodicTask):
+ run_every = crontab(minute=0, hour=3)
+ bbox = (55.26, 46.52, 15.26, 5.22)
+ store_name = 'mate.xml'
+ tag = 'drink:club-mate'
diff --git a/sublab_project/sublab_monitor/tasks.py b/sublab_project/sublab_monitor/tasks.py
index 681ce5f..982b0a3 100644
--- a/sublab_project/sublab_monitor/tasks.py
+++ b/sublab_project/sublab_monitor/tasks.py
@@ -4,10 +4,12 @@ from datetime import timedelta
from celery.task import PeriodicTask
import subprocess
import urllib2
+import urlparse
from PIL import Image, ImageOps
from StringIO import StringIO
from django.conf import settings
import os
+import re
import sublab_monitor
@@ -73,6 +75,13 @@ class ImageFetcher(object):
"""
raise NotImplementedError
+ def replace_file(self, filename, save):
+ fn = os.path.join(settings.MEDIA_ROOT, filename)
+ fn_new = os.path.join(settings.MEDIA_ROOT, 'new-%s' % filename)
+
+ save(fn_new)
+ os.rename(fn_new ,fn)
+
def run(self, **kwargs):
upstream = urllib2.urlopen(self.fetch_url).read()
image = Image.open(StringIO(upstream))
@@ -82,12 +91,16 @@ class ImageFetcher(object):
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)
+ self.replace_file(self.store_name, image.save)
+
+ if image.mode.upper() == 'RGBA':
+ image = Image.composite(image, Image.new("RGB", image.size, (255,255,255)), image)
+ image.convert("RGB")
- image.save(fn_new)
- os.rename(fn_new, fn)
+ image.thumbnail((180, 180), Image.ANTIALIAS)
+ self.replace_file('thumb_' + self.store_name, image.save)
+ return 'Done.'
class EnhancingImageFetcher(ImageFetcher):
def process_image(self, image):
@@ -107,3 +120,15 @@ class TempGraphFetcher(ImageFetcher, PeriodicTask):
run_every = timedelta(minutes=5)
fetch_url = 'http://taifun.local.sublab.org/temperature/temp-2hour.png'
store_name = 'tempgraph.png'
+
+class ReeknerSprookTempFetcher(ImageFetcher, PeriodicTask):
+ run_every = timedelta(minutes=5)
+ store_name = 'reeknersprook.png'
+
+ @property
+ def fetch_url(self):
+ url = 'http://reeknersprook.de/sublog/graph-small'
+ buf = urllib2.urlopen(url).read()
+ rel = re.search(r'src="(.*?)"', buf).group(1)
+
+ return urlparse.urljoin(url, rel)
diff --git a/sublab_project/templates/base.html b/sublab_project/templates/base.html
index 9a4bbca..8e609ab 100644
--- a/sublab_project/templates/base.html
+++ b/sublab_project/templates/base.html
@@ -107,10 +107,11 @@
{% flatblock "motd" %}
</p>
<hr>
- <a href="/webcam/" class="img"><img src="{{ MEDIA_URL }}karlheine_cam.jpg" alt="Webcam im Fenster" class="webcamthumb"></a>
+ <a href="/webcam/" class="img"><img src="{{ MEDIA_URL }}thumb_karlheine_cam.jpg" alt="Webcam im Fenster" class="webcamthumb"></a>
<hr>
- <a href="{{ MEDIA_URL }}tempgraph.png" class="img"><img src="{{ MEDIA_URL }}tempgraph.png" alt="Temperaturen im sublab" class="webcamthumb"></a>
+ <a href="{{ MEDIA_URL }}tempgraph.png" class="img"><img src="{{ MEDIA_URL }}thumb_tempgraph.png" alt="Temperaturen im sublab" class="webcamthumb"></a>
<hr>
+ <a href="http://reeknersprook.de/sublog/graph" class="img"><img src="{{ MEDIA_URL }}reeknersprook.png" alt="Temperaturen in der Lounge" class="webcamthumb"></a>
<p class="member">
<a href="{{ STATIC_URL }}pdf/sublab_ev_mitgliedsantrag.pdf">Mitglied werden</a>
</p>