neuroplane

5 inch sink display layout

Sep 20th, 2021 (edited)
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. import os
  5.  
  6. #######
  7. import json
  8. import os
  9. import sys
  10. import textwrap
  11. from time import strptime, strftime, time
  12.  
  13. import lipsum
  14.  
  15. import jmespath
  16. import requests
  17. import PIL
  18. from PIL import Image, ImageDraw, ImageFont, ImageOps
  19. import datetime
  20. from datetime import datetime, timezone, timedelta
  21. ########
  22.  
  23. picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
  24. libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
  25. if os.path.exists(libdir):
  26.     sys.path.append(libdir)
  27.  
  28. import logging
  29. from waveshare_epd import epd5in83
  30. import time
  31. from PIL import Image, ImageDraw, ImageFont
  32. import traceback
  33.  
  34. logging.basicConfig(level=logging.DEBUG)
  35.  
  36.  
  37. ### SCHEDULE
  38. apiurl = "https://x125.ru/api/public/getdayschedule"
  39.  
  40. payload = ""
  41. headers = {
  42.     "Content-Type": "application/json",
  43.     "Authorization": "Token 11609376-ff57-401e-88a4-53f4c0904fdb"
  44. }
  45.  
  46. schedule = requests.request("POST", apiurl, data=payload, headers=headers).json()
  47. print(schedule)
  48.  
  49. ###### WIKIPEDIA
  50. wikiurl = "https://ru.wikipedia.org/w/api.php"
  51. querystring = {"action": "query", "format":"json", "titles":"электрон","prop":"extracts","utf8":"true","redirects":"1","exintro":"","explaintext":""}
  52.  
  53. payload = ""
  54. headers = {"cookie": "WMF-Last-Access=14-Aug-2021; WMF-Last-Access-Global=14-Aug-2021; GeoIP=RU%3ASE%3AVladikavkaz%3A43.03%3A44.67%3Av4"}
  55.  
  56. response = requests.request("GET", wikiurl, data=payload, headers=headers, params=querystring).json()
  57. wotd = jmespath.search("query.pages.*.extract | [0]", response)
  58. print(wotd)
  59. H = 600
  60. W = 448
  61.  
  62. COL1LEFT = 20
  63. COL1RIGHT = W/2 - 20
  64. COL1CENTER = W/4
  65. COL2LEFT = W/2 + 20
  66. COL2RIGHT = W - 20
  67. CENTER = W/2
  68. im = PIL.Image.new(mode="RGB", size=(448, 600), color=(255, 255, 255))
  69. draw = ImageDraw.Draw(im)
  70. ###############################################
  71. boston = ImageFont.truetype('fonts/nhlboston.ttf', 24)
  72. robotocond = ImageFont.truetype('fonts/robotocond.ttf', 11)
  73. mach = ImageFont.truetype('fonts/mach.otf', 40)
  74. machsmall = ImageFont.truetype('fonts/mach.otf', 25)
  75. machbig = ImageFont.truetype('fonts/mach.otf', 140)
  76. unreal = ImageFont.truetype('fonts/unreal.ttf', 14)
  77. ubuntu = ImageFont.truetype('fonts/Ubuntu-M.ttf', 65)
  78. ubuntuс = ImageFont.truetype('fonts/ubuntuc.ttf', 16)
  79. kroftsman = ImageFont.truetype('fonts/kroftsman.ttf', 150)
  80. kroftsmansm = ImageFont.truetype('fonts/kroftsman.ttf', 150)
  81. minecraftia = ImageFont.truetype('fonts/minecraftia.ttf', 8)
  82. thintel = ImageFont.truetype('fonts/thintel.ttf', 16)
  83. superstar = ImageFont.truetype('fonts/superstar.ttf', 12)
  84. pixeled = ImageFont.truetype('fonts/pixeled.ttf',6)
  85. dfont = minecraftia
  86. greyFont = (128, 128, 128, 128)
  87. blackFont = (0, 0, 0)
  88. LINESTART = 30
  89. LINEHEIGHT = 20
  90. #draw.text((COL1LEFT, 30), "РАСПИСАНИЕ", font=dfont, fill=blackFont, anchor="lm")
  91. #draw.text((COL1LEFT, LINESTART + LINEHEIGHT*0), "09:00 Русский язык", font=dfont, fill=greyFont, anchor="lm")
  92. #draw.text((COL1LEFT, LINESTART + LINEHEIGHT*1), "10:00 Математика", font=dfont, fill=blackFont, anchor="lm")
  93. #draw.text((COL1LEFT, LINESTART + LINEHEIGHT*2), "10:40 Природоведение", font=dfont, fill=blackFont, anchor="lm")
  94. #draw.text((COL1LEFT, LINESTART + LINEHEIGHT*3), "13:00 Хоккей", font=dfont, fill=blackFont, anchor="lm")
  95. # draw.text((COL1RIGHT, LINESTART), "COL1R", font=dfont, fill=greyFont, anchor="rm")
  96. #draw.text((COL2LEFT, LINESTART), "COL2L", font=dfont, fill=blackFont, anchor="lm")
  97. R1C1 = R1C2 = R2C1 = R2C2 = R3C1 = R3C2 = 2
  98. studies = [{"time":"08:30","name":"Русский язык","overdue": True},{"time":"09:30","name":"Литературное чтение","overdue":True},{"time":"10:30","name":"Осетинский язык","overdue":True},{"time":"11:30","name":"ИЗО","overdue":False},{"time":"13:10","name":"Ледовая тренировка","overdue":False},{"time":"16:00","name":"Бросковая","overdue":False}]
  99. games = [{"home":"TBL","away":"CAR","homescore":"4","awayscore":"3","type":"OT"},{"home":"CBJ","away":"WSH","homescore":"3","awayscore":"5","type":"SO"},{"home":"NSH","away":"MIN","homescore":"2","awayscore":"5","type":""},{"home":"TBL","away":"CAR","homescore":"4","awayscore":"3","type":"OT"},{"home":"CBJ","away":"WSH","homescore":"3","awayscore":"5","type":"SO"},{"home":"NSH","away":"MIN","homescore":"2","awayscore":"5","type":""},{"home":"TBL","away":"CAR","homescore":"4","awayscore":"3","type":"OT"},{"home":"CBJ","away":"WSH","homescore":"3","awayscore":"5","type":"SO"},{"home":"NSH","away":"MIN","homescore":"2","awayscore":"5","type":""}]
  100. standings = [{"name":"Tampa Bay Lightning","points":"35"},{"name":"Minnesota Wild","points":"33"},{"name":"Washington Capitals","points":"32"},{"name":"Boston Bruins","points":"31"},{"name":"Columbus Blue Jackets","points":"29"},{"name":"Washington Capitals","points":"32"},{"name":"Boston Bruins","points":"31"},{"name":"Columbus Blue Jackets","points":"29"}]
  101. fieldplayers = [{"name":"Kirill Kaprizov","passes":"39","goals":"29","points":"58"},{"name":"Connor McDavid","passes":"39","goals":"29","points":"58"},{"name":"Artemiy Panarin","passes":"39","goals":"29","points":"58"},{"name":"Alex Ovechkin","passes":"39","goals":"29","points":"58"},{"name":"David Pastrnak","passes":"39","goals":"29","points":"58"},{"name":"Matt Barzal","passes":"39","goals":"29","points":"58"},{"name":"Nikita Kucherov","passes":"39","goals":"29","points":"58"}]
  102. goalies = [{"name":"Andrei Vasilevskiy","sv":".925","gaa":"2.21"},{"name":"Connor Hellebuyck","sv":".925","gaa":"2.21"},{"name":"Jordan Binnington","sv":".925","gaa":"2.21"},{"name":"Philipp Grubauer","sv":".925","gaa":"2.21"},{"name":"Tristan Jarry","sv":".925","gaa":"2.21"},{"name":"Marc-Andre Fleury","sv":".925","gaa":"2.21"},{"name":"Semyon Varlamov","sv":".925","gaa":"2.21"}]
  103.  
  104. index1 = 2
  105. textline = 16
  106.  
  107.  
  108. try:
  109.     logging.info("epd5in83 Demo")
  110.  
  111.     epd = epd5in83.EPD()
  112.     logging.info("init and Clear")
  113.     epd.init()
  114.     epd.Clear()
  115.  
  116.     # ROW 1 COLUMN 1
  117.     for lesson in schedule:
  118.         if int(lesson['time_to']) >= 0:
  119.             overduegrey = greyFont
  120.         else:
  121.             overduegrey = blackFont
  122.         draw.text((COL1LEFT, LINESTART + textline * R1C1), lesson['time'] + "   " + lesson['lesson_name'], font=dfont,
  123.                   fill=overduegrey, anchor="lm")
  124.         R1C1 = R1C1 + 1
  125.  
  126.     # ROW 1 COLUMN 2
  127.     for line in textwrap.wrap(
  128.             "Математика: с. 24 (устно).Пропись: с.12-13. Азбука: с.19 (вспомнить и пересказать сказку), правило.", 40):
  129.         draw.text((COL2LEFT, LINESTART + textline * R1C2), line, font=dfont, fill=blackFont, anchor="lm")
  130.         R1C2 = R1C2 + 1
  131.  
  132.     # ROW 2 COLUMN 1
  133.     shift = 50
  134.     for game in games:
  135.         linehome = str(game['home'])
  136.         lineaway = str(game['away'])
  137.         if game['type'] is not None:
  138.             type = str(game['type'])
  139.             draw.text((COL1RIGHT - 30, H / 3 + textline * R2C1), type, font=dfont, fill=greyFont, anchor="rm")
  140.         score = str(game['homescore']) + " : " + str(game['awayscore'])
  141.         draw.text((COL1LEFT + shift, H / 3 + textline * R2C1), linehome, font=dfont, fill=blackFont, anchor="lm")
  142.         draw.text((COL1RIGHT - shift, H / 3 + textline * R2C1), lineaway, font=dfont, fill=blackFont, anchor="rm")
  143.         draw.text((COL1CENTER, H / 3 + textline * R2C1), score, font=dfont, fill=blackFont, anchor="mm")
  144.         R2C1 = R2C1 + 1
  145.  
  146.     # ROW 2 COLUMN 2
  147.     for team in standings:
  148.         teamname = str(team['name'])
  149.         points = str(team['points'])
  150.         draw.text((COL2LEFT, H / 3 + textline * R2C2), teamname, font=dfont, fill=blackFont, anchor="lm")
  151.         draw.text((COL2RIGHT, H / 3 + textline * R2C2), points, font=dfont, fill=blackFont, anchor="rm")
  152.         R2C2 = R2C2 + 1
  153.  
  154.     # ROW 3 COLUMN 1
  155.     draw.text((COL1LEFT, H / 3 * 2 + textline * R3C1), "Field player name", font=dfont, fill=blackFont, anchor="lm")
  156.     draw.text((COL1RIGHT, H / 3 * 2 + textline * R3C1), "P", font=dfont, fill=blackFont, anchor="rm")
  157.     draw.text((COL1RIGHT - 25, H / 3 * 2 + textline * R3C1), "G", font=dfont, fill=blackFont, anchor="rm")
  158.     draw.text((COL1RIGHT - 50, H / 3 * 2 + textline * R3C1), "P", font=dfont, fill=blackFont, anchor="rm")
  159.     draw.line((COL1LEFT, H / 3 * 2 + textline * (R3C1 + 1), COL1RIGHT, H / 3 * 2 + textline * (R3C1 + 1)),
  160.               fill=greyFont)
  161.     R3C1 = R3C1 + 2
  162.     for player in fieldplayers:
  163.         draw.text((COL1LEFT, H / 3 * 2 + textline * R3C1), player['name'], font=dfont, fill=blackFont, anchor="lm")
  164.         draw.text((COL1RIGHT, H / 3 * 2 + textline * R3C1), player['points'], font=dfont, fill=blackFont, anchor="rm")
  165.         draw.text((COL1RIGHT - 25, H / 3 * 2 + textline * R3C1), player['goals'], font=dfont, fill=blackFont,
  166.                   anchor="rm")
  167.         draw.text((COL1RIGHT - 50, H / 3 * 2 + textline * R3C1), player['passes'], font=dfont, fill=blackFont,
  168.                   anchor="rm")
  169.  
  170.         R3C1 = R3C1 + 1
  171.  
  172.     # ROW 3 COLUMN2
  173.  
  174.     draw.text((COL2LEFT, H / 3 * 2 + textline * R3C2), "Goalie name", font=dfont, fill=blackFont, anchor="lm")
  175.     draw.text((COL2RIGHT, H / 3 * 2 + textline * R3C2), "GAA", font=dfont, fill=blackFont, anchor="rm")
  176.     draw.text((COL2RIGHT - 35, H / 3 * 2 + textline * R3C2), "SV", font=dfont, fill=blackFont, anchor="rm")
  177.     # draw.text((COL2RIGHT - 50, H / 3 * 2 + textline * R3C2), "P", font=thintel, fill=blackFont, anchor="rm")
  178.     draw.line((COL2LEFT, H / 3 * 2 + textline * (R3C2 + 1), COL2RIGHT, H / 3 * 2 + textline * (R3C2 + 1)),
  179.               fill=greyFont)
  180.     R3C2 = R3C2 + 2
  181.     for goalie in goalies:
  182.         draw.text((COL2LEFT, H / 3 * 2 + textline * R3C2), goalie['name'], font=dfont, fill=blackFont, anchor="lm")
  183.         draw.text((COL2RIGHT, H / 3 * 2 + textline * R3C2), goalie['gaa'], font=dfont, fill=blackFont, anchor="rm")
  184.         draw.text((COL2RIGHT - 35, H / 3 * 2 + textline * R3C2), goalie['sv'], font=dfont, fill=blackFont, anchor="rm")
  185.         # draw.text((COL2RIGHT - 50, H / 3 * 2 + textline * R3C2), goalie['passes'], font=thintel, fill=blackFont, anchor="rm")
  186.  
  187.         R3C2 = R3C2 + 1
  188.     index = 2
  189.     textline = 16
  190.     draw.line((COL1LEFT - 10, H / 3, COL2RIGHT + 10, H / 3), fill=greyFont)
  191.     draw.line((COL1LEFT - 10, H / 3 * 2, COL2RIGHT + 10, H / 3 * 2), fill=greyFont)
  192.  
  193.  
  194.  
  195.     logging.info("Goto Sleep...")
  196.     epd.sleep()
  197.  
  198. except IOError as e:
  199.     logging.info(e)
  200.  
  201. except KeyboardInterrupt:
  202.     logging.info("ctrl + c:")
  203.     epd5in83.epdconfig.module_exit()
  204.     exit()
RAW Paste Data