summaryrefslogtreecommitdiff
path: root/scripts/trollette.py
diff options
context:
space:
mode:
authorFlorian <stayawake@lavabit.com>2013-05-04 00:11:07 +0200
committerFlorian <stayawake@lavabit.com>2013-05-04 00:11:40 +0200
commit2f0fca884cb1b036fc74e13af718bfd23f4194ea (patch)
tree94546bf04ceaa1b72b0d01d317009c3772d13c9f /scripts/trollette.py
parentf84a06f37ea4f9b79aaa6b1aebc46d6f2c80ac78 (diff)
added trollettenscript
Diffstat (limited to 'scripts/trollette.py')
-rwxr-xr-xscripts/trollette.py68
1 files changed, 68 insertions, 0 deletions
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