From 2f0fca884cb1b036fc74e13af718bfd23f4194ea Mon Sep 17 00:00:00 2001 From: Florian Date: Sat, 4 May 2013 00:11:07 +0200 Subject: added trollettenscript --- scripts/trollette.py | 68 +++++++++++++++++++++++++++++++++++ scripts/trollette.sh | 29 +++++++++++++++ template/klocam/day/klo-dimm-1.jpg | Bin 0 -> 33451 bytes template/klocam/day/klo-dimm-2.jpg | Bin 0 -> 33390 bytes template/klocam/day/klo-dimm-3.jpg | Bin 0 -> 36657 bytes template/klocam/day/klo-dimm-4.jpg | Bin 0 -> 37704 bytes template/klocam/day/klo-dimm-5.jpg | Bin 0 -> 39905 bytes template/klocam/day/klo-dimm-6.jpg | Bin 0 -> 39879 bytes template/klocam/lastone.log | 1 + template/klocam/lounge/klo-red-1.jpg | Bin 0 -> 39390 bytes template/klocam/lounge/klo-red-2.jpg | Bin 0 -> 38998 bytes template/klocam/night/klo-blue-1.jpg | Bin 0 -> 33381 bytes template/klocam/night/klo-blue-2.jpg | Bin 0 -> 34227 bytes template/klocam/night/klo-dark-1.jpg | Bin 0 -> 15944 bytes template/klocam/night/klo-dark-2.jpg | Bin 0 -> 17041 bytes template/klocam/night/klo-dark-3.jpg | Bin 0 -> 16490 bytes template/klocam/on/klo-on-1.jpg | Bin 0 -> 48180 bytes template/klocam/on/klo-on-2.jpg | Bin 0 -> 48213 bytes template/klocam/on/klo-on-3.jpg | Bin 0 -> 48834 bytes 19 files changed, 98 insertions(+) create mode 100755 scripts/trollette.py create mode 100755 scripts/trollette.sh create mode 100644 template/klocam/day/klo-dimm-1.jpg create mode 100644 template/klocam/day/klo-dimm-2.jpg create mode 100644 template/klocam/day/klo-dimm-3.jpg create mode 100644 template/klocam/day/klo-dimm-4.jpg create mode 100644 template/klocam/day/klo-dimm-5.jpg create mode 100644 template/klocam/day/klo-dimm-6.jpg create mode 100644 template/klocam/lastone.log create mode 100644 template/klocam/lounge/klo-red-1.jpg create mode 100644 template/klocam/lounge/klo-red-2.jpg create mode 100644 template/klocam/night/klo-blue-1.jpg create mode 100644 template/klocam/night/klo-blue-2.jpg create mode 100644 template/klocam/night/klo-dark-1.jpg create mode 100644 template/klocam/night/klo-dark-2.jpg create mode 100644 template/klocam/night/klo-dark-3.jpg create mode 100644 template/klocam/on/klo-on-1.jpg create mode 100644 template/klocam/on/klo-on-2.jpg create mode 100644 template/klocam/on/klo-on-3.jpg diff --git a/scripts/trollette.py b/scripts/trollette.py new file mode 100755 index 0000000..aa07331 --- /dev/null +++ b/scripts/trollette.py @@ -0,0 +1,68 @@ +#!/usr/bin/python + +import random +import os +import time + +def choose_image(imagepath, lastonefile): + + lastonefile = os.path.join(imagepath, lastonefile) + dice = random.random() + now = time.strftime("%H", time.localtime()) + + # Do we remember the last image we sent out? + if os.path.exists(lastonefile): + + #first we decide if the previous image will be used again + if dice < 0.8: + with open(lastonefile, "r") as f: + lastone = f.readline() + return lastone + + # There is a 10% chance that the light is on + # This state is not saved in the lastonelog, so the chance, that this + # image will be serverd next time again are reduced. + # It also helps saving some energy. + if dice > 0.9: + newone = random.randint(0, len(onimages)-1) + return os.path.join(imagepath, "on", onimages[newone]) + + # Between 6 a.m. and 6 p.m. theres a good chance that the toilet is + # quite bright even if noone is there + elif now < 18 and now > 5: + newone = random.randint(0, len(dayimages)-1) + newimage = os.path.join(imagepath, "day", dayimages[newone]) + f = open(lastonefile, "w") + f.write(newimage) + f.close() + return newimage + + # At night, this place is super-dark, or blue :-) + else: + newone = random.randint(0, len(onimages)-1) + newimage = os.path.join(imagepath, "night", nightimages[newone]) + f = open(lastonefile, "w") + f.write(newimage) + f.close() + return newimage + +def read_images(imagepath): + + global dayimages + global nightimages + global onimages + + #images for different illumination settings are in on folder each + dayimages = os.listdir(os.path.join(imagepath, "day")) + nightimages = os.listdir(os.path.join(imagepath, "night")) + onimages = os.listdir(os.path.join(imagepath, "on")) + +if __name__ == "__main__": + + #Configuration stuff + imagepath = "../template/klocam" + lastonefile = "lastone.log" + + read_images(imagepath) + newimage = choose_image(imagepath, lastonefile) + print newimage diff --git a/scripts/trollette.sh b/scripts/trollette.sh new file mode 100755 index 0000000..e63663f --- /dev/null +++ b/scripts/trollette.sh @@ -0,0 +1,29 @@ +#!/bin/zsh + +WEBPATH="../" +NAME="klo" +TIMESTAMP="yes" +BILD=`python2 trollette.py` + + +TODAY=`date` +TIME=`date +"%H"` + +cp $BILD ${WEBPATH}/public/img/buffer.${NAME}.webcam.jpg &> /dev/null || exit 1 + +cp ${WEBPATH}/public/img/buffer.${NAME}.webcam.jpg ${WEBPATH}/public/img/buffer.thumb.${NAME}.webcam.jpg + +mogrify +noise Gaussian -attenuate 0.4 -adaptive-sharpen 3 -resize 208x117 ${WEBPATH}/public/img/buffer.thumb.${NAME}.webcam.jpg + +if [ x"${TIMESTAMP}" == x"yes" ]; then + if [ $TIME -lt 6 ] || [ $TIME -ge 18 ]; then + mogrify +noise Gaussian -attenuate 0.4 -adaptive-sharpen 3 -fill white -gravity SouthEast -draw "text 10,10 '${TODAY}'" ${WEBPATH}/public/img/buffer.${NAME}.webcam.jpg + else + mogrify -contrast-stretch 0 -adaptive-sharpen 3 -fill black -gravity SouthEast -draw "text 10,10 '${TODAY}'" ${WEBPATH}/public/img/buffer.${NAME}.webcam.jpg + fi + fi + + mv -f ${WEBPATH}/public/img/buffer.${NAME}.webcam.jpg ${WEBPATH}/public/img/${NAME}.webcam.jpg &> /dev/null + mv -f ${WEBPATH}/public/img/buffer.thumb.${NAME}.webcam.jpg ${WEBPATH}/public/img/thumb.${NAME}.webcam.jpg &> /dev/null + exit 0 + diff --git a/template/klocam/day/klo-dimm-1.jpg b/template/klocam/day/klo-dimm-1.jpg new file mode 100644 index 0000000..bd041cd Binary files /dev/null and b/template/klocam/day/klo-dimm-1.jpg differ diff --git a/template/klocam/day/klo-dimm-2.jpg b/template/klocam/day/klo-dimm-2.jpg new file mode 100644 index 0000000..12c2a58 Binary files /dev/null and b/template/klocam/day/klo-dimm-2.jpg differ diff --git a/template/klocam/day/klo-dimm-3.jpg b/template/klocam/day/klo-dimm-3.jpg new file mode 100644 index 0000000..d50f958 Binary files /dev/null and b/template/klocam/day/klo-dimm-3.jpg differ diff --git a/template/klocam/day/klo-dimm-4.jpg b/template/klocam/day/klo-dimm-4.jpg new file mode 100644 index 0000000..cdc7478 Binary files /dev/null and b/template/klocam/day/klo-dimm-4.jpg differ diff --git a/template/klocam/day/klo-dimm-5.jpg b/template/klocam/day/klo-dimm-5.jpg new file mode 100644 index 0000000..5e63767 Binary files /dev/null and b/template/klocam/day/klo-dimm-5.jpg differ diff --git a/template/klocam/day/klo-dimm-6.jpg b/template/klocam/day/klo-dimm-6.jpg new file mode 100644 index 0000000..b0e9b86 Binary files /dev/null and b/template/klocam/day/klo-dimm-6.jpg differ diff --git a/template/klocam/lastone.log b/template/klocam/lastone.log new file mode 100644 index 0000000..65cbb5e --- /dev/null +++ b/template/klocam/lastone.log @@ -0,0 +1 @@ +/home/bernd/Workdir/klo/images/night/klo-dark-1.jpg \ No newline at end of file diff --git a/template/klocam/lounge/klo-red-1.jpg b/template/klocam/lounge/klo-red-1.jpg new file mode 100644 index 0000000..f85d3a0 Binary files /dev/null and b/template/klocam/lounge/klo-red-1.jpg differ diff --git a/template/klocam/lounge/klo-red-2.jpg b/template/klocam/lounge/klo-red-2.jpg new file mode 100644 index 0000000..6f9d769 Binary files /dev/null and b/template/klocam/lounge/klo-red-2.jpg differ diff --git a/template/klocam/night/klo-blue-1.jpg b/template/klocam/night/klo-blue-1.jpg new file mode 100644 index 0000000..7b1d07f Binary files /dev/null and b/template/klocam/night/klo-blue-1.jpg differ diff --git a/template/klocam/night/klo-blue-2.jpg b/template/klocam/night/klo-blue-2.jpg new file mode 100644 index 0000000..7280101 Binary files /dev/null and b/template/klocam/night/klo-blue-2.jpg differ diff --git a/template/klocam/night/klo-dark-1.jpg b/template/klocam/night/klo-dark-1.jpg new file mode 100644 index 0000000..97ac312 Binary files /dev/null and b/template/klocam/night/klo-dark-1.jpg differ diff --git a/template/klocam/night/klo-dark-2.jpg b/template/klocam/night/klo-dark-2.jpg new file mode 100644 index 0000000..c06ed6c Binary files /dev/null and b/template/klocam/night/klo-dark-2.jpg differ diff --git a/template/klocam/night/klo-dark-3.jpg b/template/klocam/night/klo-dark-3.jpg new file mode 100644 index 0000000..f913a5f Binary files /dev/null and b/template/klocam/night/klo-dark-3.jpg differ diff --git a/template/klocam/on/klo-on-1.jpg b/template/klocam/on/klo-on-1.jpg new file mode 100644 index 0000000..0107cf2 Binary files /dev/null and b/template/klocam/on/klo-on-1.jpg differ diff --git a/template/klocam/on/klo-on-2.jpg b/template/klocam/on/klo-on-2.jpg new file mode 100644 index 0000000..85ea405 Binary files /dev/null and b/template/klocam/on/klo-on-2.jpg differ diff --git a/template/klocam/on/klo-on-3.jpg b/template/klocam/on/klo-on-3.jpg new file mode 100644 index 0000000..3f4a511 Binary files /dev/null and b/template/klocam/on/klo-on-3.jpg differ -- cgit v1.2.1