-
Notifications
You must be signed in to change notification settings - Fork 0
/
pos.py
30 lines (29 loc) · 1.01 KB
/
pos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
import os
import time
from ftfy import fix_text
from opengraph import OpenGraph
import urllib.request
from escpos import printer
class Pos:
def __init__(self, url):
og = OpenGraph(url)
file_name, headers = urllib.request.urlretrieve(og.image)
# call image magick to update file in place
# cmd = 'mogrify -colorspace Gray -ordered-dither h4x4a -resize 512 %s' % file_name
cmd = 'mogrify -colorspace Gray -resize 512 -unsharp 0x1 %s' % file_name
os.system(cmd)
# make an attempt to shorten the title and make it printable
title = ascii(fix_text(og.title.split('Instagram post by ').pop().split('Instagram: ').pop())).replace('\\u2022','-').replace('\'','')
p = printer.File("/dev/usb/lp0")
p.text(title)
p.text("\n")
time.sleep(2)
p.image(file_name)
time.sleep(2)
p.text("\n")
p.text(og.url)
p.cut()
print(title)
print(file_name)
urllib.request.urlcleanup()