popaad

Untitled

Jun 22nd, 2022 (edited)
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. import os
  5.  
  6. picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
  7. libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
  8. if os.path.exists(libdir):
  9.     sys.path.append(libdir)
  10.    
  11. import logging
  12. from waveshare_epd import epd2in13_V2
  13. import time
  14. from datetime import datetime
  15. from PIL import Image,ImageDraw,ImageFont
  16.  
  17. logging.basicConfig(level=logging.DEBUG)
  18.  
  19. epd = epd2in13_V2.EPD()
  20.  
  21. try:    
  22.     font52 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 52)
  23.     font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
  24.    
  25.     logging.info("init and Clear")
  26.     epd.init(epd.FULL_UPDATE)
  27.     epd.Clear(0xFF)
  28.    
  29.     # partial update
  30.     logging.info("4.show time...")
  31.        
  32.     while (True):
  33.         time_image = Image.new('1', (epd.height, epd.width), 255)
  34.         time_draw = ImageDraw.Draw(time_image)
  35.         time_draw.rectangle((0, 0, epd.height, epd.width), fill = 255)
  36.         time_draw.text((125, 61), datetime.now().strftime('%H:%M'), font = font52, fill = 0, anchor="mm")
  37.         time_draw.text((125, 122), datetime.now().strftime('%a, %d %B %Y'), font = font24, fill = 0, anchor="md")
  38.         epd.display(epd.getbuffer(time_image.transpose(Image.ROTATE_180)))
  39.        
  40.         if (datetime.now().hour == 0):
  41.             seconds_until_next_630 = (datetime.timedelta(hours=24) - (now - now.replace(hour=6, minute=30, second=0, microsecond=0))).total_seconds() % (24 * 3600)
  42.             epd.Clear(0xFF)
  43.             epd.sleep()
  44.             time.sleep(seconds_until_next_630)
  45.             epd.init(epd.FULL_UPDATE)
  46.             epd.Clear(0xFF)
  47.             continue
  48.        
  49.         now = datetime.now()
  50.         seconds_until_next_minute = 60 - now.time().second
  51.         time.sleep(seconds_until_next_minute)
  52.  
  53.        
  54. except IOError as e:
  55.     logging.info(e)
  56.    
  57. except KeyboardInterrupt:  
  58.     epd.Clear(0xFF)
  59.     epd.sleep()
  60.     logging.info("ctrl + c:")
  61.     epd2in13_V2.epdconfig.module_exit()
  62.     exit()
Add Comment
Please, Sign In to add comment