|
|
@@ -19,20 +19,69 @@ def eink_qr(args):
|
|
|
epd.Dev_exit()
|
|
|
|
|
|
def eink_qr_shorturl(args):
|
|
|
- import requests
|
|
|
- from urllib.parse import urlencode
|
|
|
- try:
|
|
|
- params = urlencode({
|
|
|
- "url": args.text,
|
|
|
- })
|
|
|
- r = requests.get('https://tinyurl.com/api-create.php?'+str(params))
|
|
|
- args.text = r.text
|
|
|
- except Exception as ex:
|
|
|
- args.text = str(ex)[:100]
|
|
|
+ import simpilib
|
|
|
+ args.text = simpilib.short_url(args.text)
|
|
|
eink_qr(args)
|
|
|
|
|
|
def eink_quote_qr(args):
|
|
|
- pass
|
|
|
+ import simpilib
|
|
|
+ import random
|
|
|
+ data = simpilib.getRedditJson("quotes","top","day")
|
|
|
+ quotes = data["data"]["children"]
|
|
|
+ q = random.choice(quotes)
|
|
|
+ # args.text = q["data"]["title"]
|
|
|
+ # eink_text(args)
|
|
|
+ text = q["data"]["title"]
|
|
|
+ url = simpilib.short_url(q["data"]["url"])
|
|
|
+
|
|
|
+ smalltext = None
|
|
|
+ if text.find(" - ") > 0:
|
|
|
+ pos = text.rfind("-")
|
|
|
+ text = text[:pos]
|
|
|
+ smalltext = text[pos+1:]
|
|
|
+
|
|
|
+ print(text)
|
|
|
+ print(smalltext)
|
|
|
+ eink_text_qr(q["data"]["title"], url, smalltext)
|
|
|
+
|
|
|
+def eink_text_qr(text, qrdata, smalltext=None):
|
|
|
+ import simpilib
|
|
|
+ from waveshare_epd import epd2in13_V2
|
|
|
+ from PIL import Image,ImageDraw
|
|
|
+ import qrcode
|
|
|
+ epd = epd2in13_V2.EPD()
|
|
|
+
|
|
|
+ base_image = Image.new('1', (epd.height, epd.width), 0)
|
|
|
+ qr = qrcode.QRCode(version=1, box_size=3, border=1)
|
|
|
+ qr.add_data(qrdata)
|
|
|
+ qr.make()
|
|
|
+ pic = qr.make_image().get_image()
|
|
|
+
|
|
|
+ text_image = Image.new('1', (base_image.width-pic.width, base_image.height), 0)
|
|
|
+ small_image = Image.new('1', (pic.width, base_image.height-pic.height), 0)
|
|
|
+
|
|
|
+ base_image.paste(pic, (base_image.width-pic.width,0), pic)
|
|
|
+ draw = ImageDraw.Draw(base_image)
|
|
|
+
|
|
|
+ epd.init(epd.FULL_UPDATE)
|
|
|
+ epd.displayPartBaseImage(epd.getbuffer(base_image))
|
|
|
+
|
|
|
+ epd.init(epd.PART_UPDATE)
|
|
|
+
|
|
|
+ text = simpilib.wrapText(text, line_width_factor=4.5)
|
|
|
+ font = simpilib.loadFontSize(text, draw, text_image, fontpath)
|
|
|
+
|
|
|
+ draw.text((0,0), text, align="center", font = font, fill = 255)
|
|
|
+ epd.displayPartial(epd.getbuffer(base_image))
|
|
|
+
|
|
|
+ if smalltext != None and len(smalltext) > 2:
|
|
|
+ smalltext = simpilib.wrapText(smalltext, line_width_factor=10)
|
|
|
+ smallfont = simpilib.loadFontSize(text, draw, small_image, fontpath)
|
|
|
+ draw.text((base_image.width-pic.width,0), smalltext, align="center", font = font, fill = 255)
|
|
|
+ epd.displayPartial(epd.getbuffer(base_image))
|
|
|
+
|
|
|
+ epd.sleep()
|
|
|
+ epd.Dev_exit()
|
|
|
|
|
|
def eink_quote(args):
|
|
|
import simpilib
|
|
|
@@ -54,7 +103,7 @@ def eink_text(args):
|
|
|
image = Image.new('1', (epd.height, epd.width), 0)
|
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
|
|
- text, longline = simpilib.wrapText(args.text, line_width_factor=7)
|
|
|
+ text = simpilib.wrapText(args.text, line_width_factor=7)
|
|
|
font = simpilib.loadFontSize(text, draw, image, fontpath)
|
|
|
|
|
|
w, h = draw.textsize(text, font=font)
|