Skip to content

Instantly share code, notes, and snippets.

@beledouxdenis
Created October 17, 2019 16:17
Show Gist options
  • Save beledouxdenis/71dad185ff409665631f0feb4dc54b17 to your computer and use it in GitHub Desktop.
Save beledouxdenis/71dad185ff409665631f0feb4dc54b17 to your computer and use it in GitHub Desktop.
Print Odoo Experience Badge
#!/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