From 73bc370e590d9181094e96d90915c26f78a14218 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Fri, 11 Jul 2014 17:52:04 +0200 Subject: [PATCH] petit demon rabbitmq --- daemon.py | 17 +++++++++++++++++ dump.py | 41 +++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 18 deletions(-) create mode 100755 daemon.py diff --git a/daemon.py b/daemon.py new file mode 100755 index 0000000..548b3f2 --- /dev/null +++ b/daemon.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import pika +import json +import dump + +conn = pika.BlockingConnection(pika.ConnectionParameters(host='civet.crans.org')) +ch = conn.channel() +ch.queue_declare(queue='CransTicket') +def callback(ch, method, properties, body): + print " [x] Received %r" % (body,) + dump.print_liste(json.loads(body)) + + +ch.basic_consume(callback, queue='CransTicket', no_ack=True) +ch.start_consuming() +conn.close() diff --git a/dump.py b/dump.py index 191adc6..7ed2924 100755 --- a/dump.py +++ b/dump.py @@ -21,17 +21,9 @@ SAMPLE_MACHINE = { # Load data crans_logo = Image.open(os.path.join(os.path.dirname(__file__), 'logo_crans.png')) -if not sys.argv[1:]: - liste = [SAMPLE_MACHINE] -else: - with open(sys.argv[1], 'r') as f: - liste = json.load(f) printer = AdafruitThermal(DEVICE, 19200, timeout=5) -printer.setDefault() # Restore printer to defaults -printer.printImage(crans_logo, True) - def print_carac(text, value): printer.justify('L') pad = 384/12 - len(text) - len(value) @@ -55,14 +47,27 @@ def show_machine(machine): # Do print -first = True +def print_liste(liste): + printer.setDefault() # Restore printer to defaults + printer.printImage(crans_logo, True) + + first = True + + for m in liste: + if not first: + print_carac('','') + first = False + show_machine(m) + + printer.println(u'Veuillez conserver ces informations en lieu sûr.'.encode(CODING)) + + printer.feed(2) -for m in liste: - if not first: - print_carac('','') - first = False - show_machine(m) - -printer.println(u'Veuillez conserver ces informations en lieu sûr.'.encode(CODING)) - -printer.feed(2) +if __name__ == '__main__': + if not sys.argv[1:]: + liste = [SAMPLE_MACHINE] + else: + with open(sys.argv[1], 'r') as f: + liste = json.load(f) + print_liste(liste) +