Browse Source

Random cat image panel

rorist 4 months ago
parent
commit
00335df2b8
3 changed files with 29 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 17 0
      node.lua
  3. 11 0
      screend.py

+ 1 - 0
.gitignore

@@ -2,5 +2,6 @@ bus.txt
 power.txt
 events.json
 spaceapi.json
+cat.jpg
 __pycache__/
 *.swp

+ 17 - 0
node.lua

@@ -75,6 +75,10 @@ util.file_watch("bus.txt", function(content)
     bus = content
 end)
 
+util.file_watch("cat.jpg", function(content)
+    cat = resource.load_image("cat.jpg")
+end)
+
 --
 -- Fragments
 --
@@ -214,6 +218,18 @@ function panel_clock()
 
 end;
 
+function panel_cat()
+
+    function draw()
+        util.draw_correct(cat, WIDTH/2-1000, 300, WIDTH, HEIGHT-150)
+    end;
+
+    return {
+        draw = draw;
+    }
+
+end;
+
 --
 -- MAIN
 --
@@ -224,6 +240,7 @@ local cycling = cycler(util.generator(function()
         return {
             panel_spaceapi(),
             panel_events(),
+            panel_cat(),
         }
     end), 8)
 

+ 11 - 0
screend.py

@@ -100,6 +100,16 @@ def clock():
         send_data('screen/analogclock/clock/set', str(since_midnight))
         time.sleep(1)
 
+def cat():
+    while True:
+        j = requests.get('http://aws.random.cat/meow').json()
+        response = requests.get(j['file'], stream=True)
+        handle = open('./cat.jpg', "wb")
+        for chunk in response.iter_content(chunk_size=512):
+            if chunk:
+                handle.write(chunk)
+        time.sleep(300)
+
 # Copied from humanize.naturalsize and s/bytes/bits/g
 def naturalsize(value, binary=False, gnu=False, format='%.1f'):
     """Format a number of byteslike a human readable filesize (eg. 10 kB).  By
@@ -186,6 +196,7 @@ if __name__ == '__main__':
         clock,
         snmp,
         spaceapi,
+        cat,
     ]
     processes = {f: Process(target=f) for f in functions}
     [p.start() for p in processes.values()] # start the processes