git.haldean.org bitpic / master bitpic.py
master

Tree @master (Download .tar.gz)

bitpic.py @masterraw · history · blame

import anims
import argparse
import img
import os
import requests
import screen

p = argparse.ArgumentParser(description="tools for interacting with bitpic server")
p.add_argument(
    "--screen", default=screen.DEFAULT_SID,
    help="which screen to change, defaults to default screen")
p.add_argument(
    "--solid", default=None, help="set screen to a solid color")
p.add_argument(
    "--image", default=None, help="set screen to an image")
p.add_argument(
    "--anim", default=None, help="set screen to an animation")
p.add_argument(
    "--brightness", type=int, default=255, help="set screen brightness")
p.add_argument(
    "--redir", default=None, help="set screen to redirect to this screen")
p.add_argument(
    "--webroot", required=True, help="set webroot of bitpic server on localhost")

args = p.parse_args()
fname = os.path.join(args.webroot, args.screen)

if args.image:
    print("setting to image {}".format(args.image))
    s = img.image_to_screen(args.image, args.brightness)
    with open(fname, 'w') as f:
        f.write(s.encode())
elif args.solid:
    print("setting solid color rgb({})".format(args.solid))
    c = [int(x) for x in args.solid.split(',')]
    s = screen.Screen([[c for _ in range(8)] for _ in range(8)], args.brightness)
    with open(fname, 'w') as f:
        f.write(s.encode())
elif args.anim:
    print("setting animation {}".format(args.anim))
    a = anims.encode(args.anim, args.brightness)
    with open(fname, 'w') as f:
        f.write(a)
elif args.redir:
    print("redirecting {} to {}".format(args.screen, args.redir))
    with open(fname, 'w') as f:
        f.write("redir/{}".format(args.redir))
else:
    print("no operation given")