Skip to content

Instantly share code, notes, and snippets.

@pidpawel
Created March 18, 2014 20:29
Show Gist options
  • Save pidpawel/9628850 to your computer and use it in GitHub Desktop.
Save pidpawel/9628850 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import serial
import random
import re
printer = serial.Serial('/dev/ttyUSB0', 9200)
if not printer.isOpen():
printer.open()
printer.write([28,46]) # wyłącz chińskie krzaczki
printer.write([27, 116, 36]) # wybierz iso 8859-2
printer.write([27, 51, 28]) # line spacing
with open('bash') as f:
content = f.read()
content = content.split('\n%\n')
randjoke = random.choice(content)
print(randjoke)
randjoke = randjoke.split('\n', 1)
title = randjoke[0]
title = re.sub('http://', '', title)
title = title.encode('iso-8859-2')
text = randjoke[1].encode('iso-8859-2')
printer.write([29,66,1]) # białe na czarnym
printer.write(title)
printer.write([0x0a])
printer.write([29,66,0]) # czarne na białym
printer.write(text)
printer.write([0x0a, 0x0a, 0x0a])
printer.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment