From 21963b4654737d403070dabfb2cf5b0521c522f4 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Mon, 23 Jan 2012 23:24:43 +0100 Subject: Improve tasks for images --- sublab_project/matekarte/tasks.py | 10 +++++----- sublab_project/sublab_monitor/tasks.py | 33 +++++++++++++++++++++++++++++---- sublab_project/templates/base.html | 5 +++-- 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" %}


- Webcam im Fenster + Webcam im Fenster
- Temperaturen im sublab + Temperaturen im sublab
+ Temperaturen in der Lounge

Mitglied werden

-- cgit v1.2.1