Created
October 17, 2019 16:17
-
-
Save beledouxdenis/71dad185ff409665631f0feb4dc54b17 to your computer and use it in GitHub Desktop.
Print Odoo Experience Badge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import base64 | |
import subprocess | |
import threading | |
import requests | |
def print_badge(barcode): | |
pdf_filename = "badge-%s.pdf" % barcode | |
pdf = requests.get('http://localhost:8069/website/action/wQJxNRJe', params={'barcode': barcode}, timeout=60).content | |
if not pdf: | |
return | |
with open(pdf_filename, "wb") as fh: | |
fh.write(base64.b64decode(pdf)) | |
p = subprocess.Popen(['lp', pdf_filename]) | |
try: | |
p.wait(10) | |
except subprocess.TimeoutExpired: | |
p.kill() | |
while True: | |
print('Enter barcode:') | |
barcode = input() | |
threading.Thread(target=print_badge, args=(barcode,)).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment