petit demon rabbitmq
This commit is contained in:
parent
a3185bdce4
commit
73bc370e59
2 changed files with 40 additions and 18 deletions
17
daemon.py
Executable file
17
daemon.py
Executable 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()
|
29
dump.py
29
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)
|
||||
|
||||
for m in liste:
|
||||
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.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)
|
||||
|
||||
printer.feed(2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue