Exemple #1
0
def main():
	parser = argparse.ArgumentParser()
	parser.add_argument('-host', '--host', type = str, default = "localhost")
	parser.add_argument('-p', '--port', type = int, default = 4242)
	parser.add_argument('-d', '--display', type = int, choices = [0, 1, 2, 3])
	parser.add_argument('-t', '--type', choices = ['text', 'time', 'sequence'])
	parser.add_argument('-v', '--value', type = str)
	parser.add_argument('-pr', '--priority', type = int, default = 0)
	parser.add_argument('-c', '--client', type = str)
	parser.add_argument('-i', '--interval', type = float, default = 5.0)
	parser.add_argument('-s', '--state', choices = ['on', 'off', 'toggle'])
	parser.add_argument('-si', '--stop-indicator', choices = ['on', 'off', 'toggle'])
	args = parser.parse_args()
	
	client = ibis.Client(args.host, args.port)
	
	if args.state == 'on':
		if args.display:
			client.set_enabled(args.display, True)
		else:
			client.set_enabled(-1, True)
	elif args.state == 'off':
		if args.display:
			client.set_enabled(args.display, False)
		else:
			client.set_enabled(-1, False)
	elif args.state == 'toggle':
		if args.display:
			client.set_enabled(args.display, 'toggle')
		else:
			client.set_enabled(-1, 'toggle')
	
	if args.type == 'text':
		client.set_text(args.display, args.value, priority = args.priority, client = args.client)
	elif args.type == 'time':
		client.set_time(args.display, args.value, priority = args.priority, client = args.client)
	elif args.type == 'sequence':
		sequence = []
		items = args.value.split("|")
		for item in items:
			try:
				parts = item.split("~")
				duration = float(parts[-1])
				item = "~".join(parts[:-1])
			except:
				duration = None
			
			if re.match(r"^.*%[-a-zA-Z].*$", item):
				sequence.append(client.make_time(item, duration))
			else:
				sequence.append(client.make_text(item, duration))
		client.set_sequence(args.display, sequence, args.interval, priority = args.priority, client = args.client)
	
	if args.stop_indicator == 'on':
		client.set_stop_indicator(args.display, True)
	elif args.stop_indicator == 'off':
		client.set_stop_indicator(args.display, False)
	elif args.stop_indicator == 'toggle':
		client.set_stop_indicator(args.display, 'toggle')
Exemple #2
0
def main():
	def _on_properties_changed(self, *_args, **kw):
		if _args and 'PlaybackStatus' in _args[1] and _args[1]['PlaybackStatus'] != 'Playing':
			client.set_text(args.display, "Paused", priority = args.pause_priority, client = args.client)
			client.set_stop_indicator(args.display, False)
		else:
			data = player.Metadata
			title = unicode(data['xesam:title'])
			artist = unicode(", ".join(data['xesam:artist']))
			album = unicode(data['xesam:album'])
			timestamp = datetime.strptime(unicode(data['xesam:contentCreated']), "%Y-%m-%dT%H:%M:%S")
			year = timestamp.year
			
			sequence = []
			sequence.append(client.make_text(title))
			sequence.append(client.make_text(artist))
			sequence.append(client.make_text("%s (%i)" % (album, year)))
			client.set_sequence(args.display, sequence, args.sequence_interval, priority = args.music_priority, client = args.client)
			client.set_stop_indicator(args.display, True)
	
	parser = argparse.ArgumentParser()
	parser.add_argument('-host', '--host', type = str, default = "localhost")
	parser.add_argument('-p', '--port', type = int, default = 4242)
	parser.add_argument('-d', '--display', type = int, choices = (0, 1, 2, 3))
	parser.add_argument('-mpr', '--music_priority', type = int, default = 0)
	parser.add_argument('-ppr', '--pause_priority', type = int, default = 0)
	parser.add_argument('-cl', '--client', type = str, default = "music_info.py")
	parser.add_argument('-pl', '--player', type = str, default = "spotify")
	parser.add_argument('-si', '--sequence-interval', type = int, default = 3)
	args = parser.parse_args()
	
	client = ibis.Client(args.host, args.port)
	
	DBusGMainLoop(set_as_default = True)
	uri = "org.mpris.MediaPlayer2.%s" % args.player.lower()
	player = Player(dbus_interface_info = {'dbus_uri': uri})
	player.PropertiesChanged = _on_properties_changed
	_on_properties_changed(None)
	mloop = gobject.MainLoop()
	mloop.run()
Exemple #3
0
def main():
	parser = argparse.ArgumentParser()
	parser.add_argument('-host', '--host', type = str, default = "localhost")
	parser.add_argument('-p', '--port', type = int, default = 4242)
	parser.add_argument('-d', '--display', type = int, choices = (0, 1, 2, 3))
	parser.add_argument('-pr', '--priority', type = int, default = 0)
	parser.add_argument('-cl', '--client', type = str, default = "countdown.py")
	parser.add_argument('-f', '--format', type = str, default = "%(what)s in %(days)id %(hours)02i:%(minutes)02i:%(seconds)02i",
		help = "The format to display the countdown in. Variables: %%(what)s, %%(days)i, %%(hours)02i, %%(minutes)02i, %%(seconds)02i")
	parser.add_argument('-w', '--what', type = str, default = "Event")
	parser.add_argument('-t', '--target', type = str, required = True, help = "The target to count down to. Format: %%d.%%m.%%Y %%H:%%M:%%S")
	parser.add_argument('-e', '--end-text', type = str, default = "COUNTDOWN OVER!")
	args = parser.parse_args()
	
	client = ibis.Client(args.host, args.port)
	target = datetime.datetime.strptime(args.target, "%d.%m.%Y %H:%M:%S")
	
	while True:
		now = datetime.datetime.now()
		delta = target - now
		seconds = delta.total_seconds()
		
		if seconds < 0:
			break
		
		minutes, seconds = divmod(seconds, 60)
		hours, minutes = divmod(minutes, 60)
		days, hours = divmod(hours, 24)
		
		if "seconds" in args.format:
			interval = 1
		else:
			interval = 60
		
		text = args.format % {'what': args.what, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds}
		client.set_text(args.display, text, priority = args.priority, client = args.client)
		time.sleep(interval)
	
	client.set_stop_indicator(args.display, True)
	client.set_text(args.display, args.end_text, priority = args.priority, client = args.client)
Exemple #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-host', '--host', type=str, default="localhost")
    parser.add_argument('-p', '--port', type=int, default=4242)
    parser.add_argument('-d', '--display', type=int, choices=(0, 1, 2, 3))
    parser.add_argument('-pr', '--priority', type=int, default=0)
    parser.add_argument('-cl',
                        '--client',
                        type=str,
                        default="weather_display.py")
    parser.add_argument('-dn', '--duration', type=float, default=5.0)
    parser.add_argument('-c',
                        '--city',
                        type=str,
                        required=True,
                        help="The city to fetch weather data for")
    parser.add_argument('-m',
                        '--mode',
                        type=str,
                        choices=('current', 'forecast-daily',
                                 'forecast-hourly'),
                        default='current')
    parser.add_argument('-i', '--items', type=int, default=1)
    parser.add_argument('-f',
                        '--format',
                        type=str,
                        choices=('detailed', 'brief', 'minimal'),
                        default='detailed')
    args = parser.parse_args()

    client = ibis.Client(args.host, args.port)

    try:
        if args.mode == 'current':
            weather = _get_current_weather(args.city)
            if args.format == 'detailed':
                sequence = []
                sequence.append(
                    client.make_text("%(description)s" % weather['weather'][0],
                                     args.duration))
                sequence.append(
                    client.make_text("Temp: %(temp).1fC" % weather['main'],
                                     args.duration))
                sequence.append(
                    client.make_text(
                        "Wind: %(speed).1f km/h from %(deg)s" %
                        weather['wind'], args.duration))
                sequence.append(
                    client.make_text(
                        "Hum: %(humidity)i%%, %(pressure).1f hPa" %
                        weather['main'], args.duration))
                sequence.append(
                    client.make_text(
                        "Cloudiness: %(all)i%%" % weather['clouds'],
                        args.duration))
                sequence.append(
                    client.make_text(
                        "Sun from %s to %s" %
                        (weather['sys']['sunrise'].strftime("%H:%M"),
                         weather['sys']['sunset'].strftime("%H:%M")),
                        args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)
            elif args.format == 'brief':
                sequence = []
                sequence.append(
                    client.make_text("%(description)s" % weather['weather'][0],
                                     args.duration))
                sequence.append(
                    client.make_text(
                        "%.1fC, %.1f km/h, %i%%" %
                        (weather['main']['temp'], weather['wind']['speed'],
                         weather['main']['humidity']), args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)
            elif args.format == 'minimal':
                client.set_text(
                    args.display,
                    "%.1f / %.1f / %i / %.1f" %
                    (weather['main']['temp'], weather['wind']['speed'],
                     weather['main']['humidity'], weather['main']['pressure']),
                    priority=args.priority,
                    client=args.client)

        elif args.mode == 'forecast-daily':
            weather = _get_daily_forecast_weather(args.city, args.items)
            if args.format == 'detailed':
                sequence = []
                for day in weather['list']:
                    sequence.append(
                        client.make_text(
                            "(%s) %s, %i%% cloudy" %
                            (day['dt'].strftime("%a"),
                             day['weather'][0]['main'], day['clouds']),
                            args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %.1f %.1f %.1f %.1f" %
                            (day['dt'].strftime("%a"), day['temp']['morn'],
                             day['temp']['day'], day['temp']['eve'],
                             day['temp']['night']), args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %.1f km/h from %s" %
                            (day['dt'].strftime("%a"), day['speed'],
                             day['deg']), args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %i%%, %.1f hPa" %
                            (day['dt'].strftime("%a"), day['humidity'],
                             day['pressure']), args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) Precip: %.1fmm" %
                            (day['dt'].strftime("%a"), day['rain']),
                            args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)
            elif args.format == 'brief':
                sequence = []
                for day in weather['list']:
                    sequence.append(
                        client.make_text(
                            "(%s) %s, %.1f-%.1fC" %
                            (day['dt'].strftime("%a"),
                             day['weather'][0]['main'], day['temp']['min'],
                             day['temp']['max']), args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %.1f km/h, %i%%" %
                            (day['dt'].strftime("%a"), day['speed'],
                             day['humidity']), args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)
            elif args.format == 'minimal':
                sequence = []
                for day in weather['list']:
                    sequence.append(
                        client.make_text(
                            "(%s) %.1f / %.1f / %i" %
                            (day['dt'].strftime("%a"), day['temp']['day'],
                             day['speed'], day['humidity']), args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)

        elif args.mode == 'forecast-hourly':
            weather = _get_hourly_forecast_weather(args.city)
            if args.format == 'detailed':
                sequence = []
                for time in weather['list'][:args.items]:
                    sequence.append(
                        client.make_text(
                            "(%s) %s, %.1fC" %
                            (time['dt'].strftime("%H:%M"),
                             time['weather'][0]['main'], time['main']['temp']),
                            args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %i%%, %.1f hPa" %
                            (time['dt'].strftime("%H:%M"),
                             time['main']['humidity'],
                             time['main']['pressure']), args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %.1f km/h from %s" %
                            (time['dt'].strftime("%H:%M"),
                             time['wind']['speed'], time['wind']['deg']),
                            args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %i%% cloudy" % (time['dt'].strftime("%H:%M"),
                                                  time['clouds']['all']),
                            args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)
            elif args.format == 'brief':
                sequence = []
                for time in weather['list'][:args.items]:
                    sequence.append(
                        client.make_text(
                            "(%s) %s, %.1fC" %
                            (time['dt'].strftime("%H:%M"),
                             time['weather'][0]['main'], time['main']['temp']),
                            args.duration))
                    sequence.append(
                        client.make_text(
                            "(%s) %.1f km/h, %i%%" %
                            (time['dt'].strftime("%H:%M"),
                             time['wind']['speed'], time['main']['humidity']),
                            args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)
            elif args.format == 'minimal':
                sequence = []
                for time in weather['list'][:args.items]:
                    sequence.append(
                        client.make_text(
                            "(%s) %.1f / %.1f / %i" %
                            (time['dt'].strftime("%H:%M"),
                             time['main']['temp'], time['wind']['speed'],
                             time['main']['humidity']), args.duration))
                client.set_sequence(args.display,
                                    sequence,
                                    args.duration,
                                    priority=args.priority,
                                    client=args.client)
    except WeatherException:
        client.set_stop_indicator(args.display, True)
        client.set_text(args.display,
                        "Couldn't fetch weather.",
                        priority=args.priority,
                        client=args.client)
Exemple #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-host', '--host', type=str, default="localhost")
    parser.add_argument('-p', '--port', type=int, default=4242)
    parser.add_argument('-d', '--display', type=int, choices=(0, 1, 2, 3))
    parser.add_argument('-pr', '--priority', type=int, default=0)
    parser.add_argument('-cl', '--client', type=str, default="random_train.py")
    parser.add_argument('-si', '--sequence-interval', type=int, default=5)
    parser.add_argument('-db',
                        '--database',
                        type=str,
                        default="db_stations.db")
    parser.add_argument('-j',
                        '--jingle',
                        type=str,
                        default="station_jingle.wav")
    parser.add_argument('-ij',
                        '--info-jingle',
                        type=str,
                        default="info_jingle.wav")
    parser.add_argument('-sj',
                        '--stop-jingle',
                        type=str,
                        default="stop_jingle.wav")
    parser.add_argument('-q', '--quiet', action='store_true')
    args = parser.parse_args()

    client = ibis.Client(args.host, args.port)

    db = sqlite3.connect(args.database)
    cur = db.cursor()
    cur.execute("SELECT * FROM `stations`")
    stations = [row[1] for row in cur.fetchall()]

    while True:
        num_stops = random.randint(3, 20)
        stops = random.sample(stations, num_stops)
        target = stops[-1]
        train_type = random.choice(["RB", "RE", "S"])
        train_number = random.randint(1, 99)
        has_stopped = True

        print "%s%i %s" % (train_type, train_number, target)

        for i in range(num_stops):
            stop = stops[i]
            direction = random.choice(["links", "rechts"])
            will_stop = random.choice([True, False])
            cycle_interval = random.uniform(10, 30)

            if direction == "links":
                if will_stop:
                    print "    [S] <", stop
                else:
                    print "        <", stop
            elif direction == "rechts":
                if will_stop:
                    print "    [S] >", stop
                else:
                    print "        >", stop

            client.set_stop_indicator(args.display, False)

            idle_sequence = []
            idle_sequence.append(
                client.make_text("%s%i %s" %
                                 (train_type, train_number, target)))
            idle_sequence.append(client.make_time("%d.%m.%Y %H:%M"))
            client.set_sequence(args.display,
                                idle_sequence,
                                args.sequence_interval,
                                priority=args.priority,
                                client=args.client)

            if not args.quiet and has_stopped:
                os.popen("aplay -q %s" % args.info_jingle)
                os.popen(
                    (u"espeak -v mb/mb-de5 -s 40 '%s %i nach %s'" %
                     (train_type, train_number, tts_modify(target).replace(
                         "'", "\\'"))).encode('utf-8'))

            wait_time = random.uniform(5, 30)
            time.sleep(wait_time)

            sequence = []
            sequence.append(client.make_text("Nächster Halt:"))
            sequence.append(client.make_text(stop))
            sequence.append(client.make_text("Ausstieg %s" % direction))
            client.set_sequence(args.display,
                                sequence,
                                args.sequence_interval,
                                priority=args.priority,
                                client=args.client)

            if not args.quiet:
                os.popen("aplay -q %s" % args.jingle)
                if i == num_stops - 1:
                    os.popen((
                        u"espeak -v mb/mb-de5 -s 40 'Nähxter Halt: %s. Endstation. Bitte aussteigen. Ausstieg in Fahrtrichtung %s.'"
                        % (tts_modify(stop).replace(
                            "'", "\\'"), direction)).encode('utf-8'))
                else:
                    os.popen((
                        u"espeak -v mb/mb-de5 -s 40 'Nähxter Halt: %s. Ausstieg in Fahrtrichtung %s.'"
                        % (tts_modify(stop).replace(
                            "'", "\\'"), direction)).encode('utf-8'))

            if will_stop:
                first_sleep = random.uniform(0, cycle_interval)
                second_sleep = cycle_interval - first_sleep
                time.sleep(first_sleep)

                client.set_stop_indicator(args.display, True)

                if not args.quiet:
                    os.popen("aplay -q %s" % args.stop_jingle)

                time.sleep(second_sleep)
            else:
                time.sleep(cycle_interval)

            has_stopped = will_stop

        print ""
def main():
    display = pylcd.ks0108.Display(backend=pylcd.GPIOBackend,
                                   pinmap=PINMAP,
                                   debug=False)
    draw = pylcd.ks0108.DisplayDraw(display)
    display.commit(full=True)
    fb2 = ibis.simulation.DisplayFont(
        "/home/pi/projects/pyIBIS/simulation-font/bold/.fontmap", spacing=2)
    fb1 = ibis.simulation.DisplayFont(
        "/home/pi/projects/pyIBIS/simulation-font/bold/.fontmap", spacing=1)
    fn2 = ibis.simulation.DisplayFont(
        "/home/pi/projects/pyIBIS/simulation-font/narrow/.fontmap", spacing=2)
    fn1 = ibis.simulation.DisplayFont(
        "/home/pi/projects/pyIBIS/simulation-font/narrow/.fontmap", spacing=1)
    simulator = ibis.simulation.DisplaySimulator((fb2, fb1, fn2, fn1))
    client = ibis.Client('localhost', 4242)

    old_active = True
    old_text = ""
    while True:
        now = datetime.datetime.now()
        texts = client.get_current_text()
        indicators = client.get_stop_indicators()

        active = False
        for idx in range(4):
            if texts[idx] or indicators[idx]:
                active = True
                break

        display.clear()
        redraw = False

        if active:
            old_text = ""
            draw.text("IBIS Monitor", 2, ('middle', 0, 13), 12,
                      "/home/pi/.fonts/truetype/arialbd.ttf")
            draw.text(now.strftime("%H:%M:%S"), ('right', 0, 125),
                      ('middle', 0, 13), 12,
                      "/home/pi/.fonts/truetype/arialbd.ttf")

            for idx in range(4):
                bg_color = inactive_color = (255, 255,
                                             255) if indicators[idx] else (0,
                                                                           0,
                                                                           0)
                active_color = (0, 0, 0) if indicators[idx] else (255, 255,
                                                                  255)
                simulator.generate_image(
                    texts[idx] if texts[idx] else " ",
                    "/home/pi/projects/pyLCD/display%i.png" % idx,
                    dotsize=1,
                    dotspacing=0,
                    inactive_color=inactive_color,
                    active_color=active_color,
                    bg_color=bg_color)
                draw.rectangle(2, 13 + idx * 13, 125, 24 + idx * 13)
                draw.image("/home/pi/projects/pyLCD/display%i.png" % idx,
                           4,
                           15 + idx * 13,
                           condition='red > 0')
                redraw = True
        else:
            text = now.strftime("%H:%M")
            if text != old_text:
                draw.text(text, 'center', 'middle', 50,
                          "/home/pi/.fonts/truetype/arialbd.ttf")
                old_text = text
                redraw = True
            else:
                time.sleep(3)
                redraw = False

        if not old_active and active:
            display.set_brightness(1023)

        if redraw:
            display.commit()
            time_needed = (datetime.datetime.now() - now).total_seconds()
            print "%.2f seconds needed to redraw" % time_needed

        if old_active and not active:
            display.set_brightness(10)

        old_active = active