Text Clock in other language

Hi

I have created my own TextClock in Swiss German. But it can easily be adopted to other languages.
But you need a server running that pushes a new image every minute.

It is in python and uses Pillow to generate the webp format and then pixlet to publish.


import os
from PIL import Image, ImageDraw, BdfFontFile, ImageFont
from datetime import datetime, timedelta

Stunden = ['zwölfi', 'eis', 'zwei', 'drüü', 'vieri', 'föifi', 'sächsi', 'siebni', 'achti', 'nüüni', 'zähni', 'elfi']
Minuten = ['punkt', 'ein ab', 'zwei ab', 'drü ab', 'vier ab', 'foif ab', 'sechs ab', 'siebe ab', 'acht ab', 'nün ab', \
           'zäh ab', 'elf ab', 'zwölf ab', 'drittzäh ab', 'vierzäh ab', 'viertel ab', 'sächzäh ab', 'siebzäh ab', \
           'achtzäh ab', 'nünzäh ab', \
           'zwänzg ab', 'einezwänzg ab', 'zweiezwänzg ab', 'drüezwänzg ab', 'vierezwänzg ab', 'foifezwänzg ab', \
           'sechsezwänzg ab', 'siebnezwänzg ab', \
           'achtezwänzg ab', 'nünezwänzg ab', \
           'halbi', 'ein ab halbi', 'zwei ab halbi', 'drüe ab halbi', 'vier ab halbi', 'foif ab halbi', 'sech ab halbi', \
           'siebe ab halbi', 'acht ab halbi', 'nün ab halbi', \
           'zwänzg vor', 'nünzäh vor', 'achtzäh vor', 'siebzäh vor', 'sechzäh vor', 'viertel vor', 'vierzäh vor', \
           'drizäh vor', 'zwölf vor', 'elf vor', \
           'zäh vor', 'nün vor', 'acht vor', 'siebe vor', 'sächs vor', 'foif vor', 'vier vor', 'drü vor', 'zwei vor', \
           'ein vor'  ]


images = []
width = 32
center = 16
line3 = ""

f="/home/pixlet/build/pixlet/fonts/tb-8.bdf"

fp = open(f, "rb")
p = BdfFontFile.BdfFontFile(fp)
p.save(f)
font1 = ImageFont.load("/home/pixlet/build/pixlet/fonts/tb-8.pil")

if (1==1):
        hours = datetime.now().hour
        minutes = datetime.now().minute

        

        if (minutes < 30):
            line1 = Minuten[minutes] 
            line2 = Stunden[hours%12]
        else: 
            line1 = Minuten[minutes] 
            line2 = Stunden[(hours+1)%12]
        
        
 #split to 3 lines is text is too long 
        if(len(line1)>12):       
          if(line1.find("ab")>0):
            temp  = line1[line1.find("ab"):len(line1)]
            line1 = line1[0:line1.find("ab")]
            line3 = line2
            line2 = temp
        
          if(line1.find("vor")>0):
            temp  = line1[line1.find("vor"):len(line1)]
            line1 = line1[0:line1.find("vor")]
            line3 = line2
            line2 = temp
            
            
        print("1:", line1)
        print("2:", line2)
        print("3:", line3)
        

for i in range(0, 32):
    im = Image.new('RGBA', (64, 32), (0,0,0,0))
    draw = ImageDraw.Draw(im)


    #any image you like 
    im2 = Image.open("/home/pixlet/runningman.png")
    #draw texbox 
    
    draw.line([(63,0), (63-i*2,0)], fill="#500f", width = 1 )
    draw.line([(63,0), (63,i)], fill="#500f", width = 1 )
    draw.line([(0,31), (0,31-i)], fill="#500f", width = 1 )
    draw.line([(0,31), (i*2,31)], fill="#500f", width = 1 )
    
    basewidth = 20
    wpercent = (basewidth/float(im2.size[0]))
    hsize = int((float(im2.size[1])*float(wpercent)))
    im3 = im2.resize((basewidth,hsize), Image.ANTIALIAS)
    
    im.paste(im3,(40,12))
    
    draw.text((3, 2), line1, fill='#0f0f', font=font1)
    draw.text((10, 11), line2, fill='#ffff', font=font1)
    draw.text((15, 20), line3, fill='#f0ff', font=font1)
    #draw.rectangle([(1,16), (2,17)], fill="#ffff" )
    #draw.rectangle([(62,1), (62,9)], fill="#000f" )
    
   
    images.append(im)    

    
    
 #save webp format    
images[0].save('time.webp', 'webp',
               save_all=True, append_images=images[1:], optimize=False, duration=40, loop=0, quality=100)
 #call shell script to publish using pixlet API 
os.system('sh /home/pixlet/publish.sh time')
1 Like