petit demon rabbitmq

This commit is contained in:
Daniel STAN 2014-07-11 17:52:04 +02:00
parent a3185bdce4
commit 73bc370e59
2 changed files with 40 additions and 18 deletions

17
daemon.py Executable file
View file

@ -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()

41
dump.py
View file

@ -21,17 +21,9 @@ SAMPLE_MACHINE = {
# Load data # Load data
crans_logo = Image.open(os.path.join(os.path.dirname(__file__), 'logo_crans.png')) 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 = AdafruitThermal(DEVICE, 19200, timeout=5)
printer.setDefault() # Restore printer to defaults
printer.printImage(crans_logo, True)
def print_carac(text, value): def print_carac(text, value):
printer.justify('L') printer.justify('L')
pad = 384/12 - len(text) - len(value) pad = 384/12 - len(text) - len(value)
@ -55,14 +47,27 @@ def show_machine(machine):
# Do print # 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 __name__ == '__main__':
if not first: if not sys.argv[1:]:
print_carac('','') liste = [SAMPLE_MACHINE]
first = False else:
show_machine(m) with open(sys.argv[1], 'r') as f:
liste = json.load(f)
printer.println(u'Veuillez conserver ces informations en lieu sûr.'.encode(CODING)) print_liste(liste)
printer.feed(2)