fintic-tracker/stockTicker.py
2023-09-20 15:18:32 +08:00

9993 lines
546 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (C) 2020 Fintic, finticofficial@gmail.com
#
# This file is part of Fintic project, developed by Neythen Treloar and Justin Dunn
#
# stockTicker can not be copied and/or distributed without the express
# permission of Fintic
import random
import sys, select
import os
import threading
from PIL import Image, ImageDraw, ImageFont, ImageSequence
Image.init()
import pytz
import time
import csv
import requests
import pexpect
from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics
from rgbmatrix.graphics import *
from multiprocessing import Process
import traceback
import json
from datetime import datetime
import matplotlib.colors as mcolors
ny_zone = pytz.timezone('America/New_York')
gmt_zone = pytz.timezone('Etc/GMT')
gmt1_zone = pytz.timezone('Etc/GMT+1')
gmt2_zone = pytz.timezone('Etc/GMT+2')
gmt3_zone = pytz.timezone('Etc/GMT+3')
gmt4_zone = pytz.timezone('Etc/GMT+4')
gmt5_zone = pytz.timezone('Etc/GMT+5')
gmt6_zone = pytz.timezone('Etc/GMT+6')
gmt7_zone = pytz.timezone('Etc/GMT+7')
gmt8_zone = pytz.timezone('Etc/GMT+8')
gmt9_zone = pytz.timezone('Etc/GMT+9')
gmt10_zone = pytz.timezone('Etc/GMT+10')
gmt11_zone = pytz.timezone('Etc/GMT+11')
gmt12_zone = pytz.timezone('Etc/GMT+12')
gmtn1_zone = pytz.timezone('Etc/GMT-1')
gmtn2_zone = pytz.timezone('Etc/GMT-2')
gmtn3_zone = pytz.timezone('Etc/GMT-3')
gmtn4_zone = pytz.timezone('Etc/GMT-4')
gmtn5_zone = pytz.timezone('Etc/GMT-5')
gmtn6_zone = pytz.timezone('Etc/GMT-6')
gmtn7_zone = pytz.timezone('Etc/GMT-7')
gmtn8_zone = pytz.timezone('Etc/GMT-8')
gmtn9_zone = pytz.timezone('Etc/GMT-9')
gmtn10_zone = pytz.timezone('Etc/GMT-10')
gmtn11_zone = pytz.timezone('Etc/GMT-11')
gmtn12_zone = pytz.timezone('Etc/GMT-12')
gmtn13_zone = pytz.timezone('Etc/GMT-13')
gmtn14_zone = pytz.timezone('Etc/GMT-14')
ny_timezone = pytz.timezone('America/New_York')
london_timezone = pytz.timezone('Europe/London')
tokyo_timezone = pytz.timezone('Asia/Tokyo')
au_timezone = pytz.timezone('Australia/Sydney')
dubai_timezone = pytz.timezone('Asia/Dubai')
la_timezone = pytz.timezone('America/Los_Angeles')
cn_timezone = pytz.timezone('Asia/Shanghai')
paris_timezone = pytz.timezone('Europe/Paris')
in_timezone = pytz.timezone('Asia/Kolkata')
auck_timezone = pytz.timezone('Pacific/Auckland')
bang_timezone = pytz.timezone('Asia/Bangkok')
istan_timezone = pytz.timezone('Europe/Istanbul')
place_featuretitle = False
def getInput(Block=False):
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
msg = sys.stdin.read(1)
#sys.stdin.flush()
else:
msg = ''
return msg
class StockTicker():
def __init__(self):
#Define global resources
self.symbols = []
self.delay = 0.02
self.greenORred = (255, 255, 255)
#self.blank = Image.open('logos/blank.png')
self.blank = Image.new('RGB', (10, 32))
self.running = True
settings = json.load(open('csv/general_settings.json', 'r'))
self.brightness = settings['brightness']*10
# Configuration for the matrix
options = RGBMatrixOptions()
options.rows = 32
options.cols = 64
options.chain_length = 2
options.parallel = 1
options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat'
options.gpio_slowdown = 2
options.brightness = self.brightness
self.matrix = RGBMatrix(options = options)
#sys.exit()
self.points = True # display crypto change in points or percent
self.functions = {'Stocks': self.getStockImage, 'Crypto': self.getCryptoImage, 'Forex': self.getForexImage, 'Sector Performance': self.getSectorImage,
'Daily Forecast':self.getDailyWeatherImage, 'Current Weather': self.getTodayWeatherImage, 'Jokes': self.getJokesImage, 'Place (Reddit)': self.getPlaceImage,
'Sports (Team Stats)':lambda : self.getLeagueTableImage('premier_league'), 'Sports (Past Games)': lambda:self.getLeagueImage('NBA', 'past'),
'Sports (Upcoming Games)': lambda : self.getLeagueImage('NHL', 'future'), 'Sports (Live Games)': lambda: self.getLeagueImage('NBA', 'live'),
'News':self.getNewsImage, 'Custom Messages': self.getUserMessages, 'Commodities': self.getCommoditiesImage, 'Indices': self.getIndicesImage, 'Movies': self.getMoviesImage, 'Gainers, Losers, Active': self.getMarketImage,
'Economic Calendar': self.getEconomicImage, 'IPO Calendar':self.getIpoImage, 'IPO Calendar Prof':self.getIpoProfessional, 'Economic Calendar Prof': self.getEconomicProfessional, 'Gainers, Losers, Active Prof': self.getMarketProfessional,
'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional, 'Jokes Prof': self.getJokesProfessional, 'Place (Reddit) Prof': self.getPlaceImageProfessional,
'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional, 'Sector Performance Prof': self.getSectorProfessional,
'Daily Forecast Prof':self.getDailyWeatherProfessional, 'Sports (Team Stats) Prof':lambda : self.getLeagueTableProfessional('NHL'), 'Sports (Upcoming Games) Prof': lambda : self.getLeagueProfessional('NHL', 'future'),
'Sports (Past Games) Prof': lambda : self.getLeagueProfessional('NBA', 'past'), 'Custom Messages Prof': self.getUserMessagesProfessional, 'Custom Images Prof': self.getUserImagesProfessional, 'Movies Prof': self.getMoviesProfessional, 'Sports (Live Games) Prof': lambda : self.getLeagueProfessional('NBA', 'live')}
self.JSONs = {'Stocks': 'csv/stocks_settings.json', 'Crypto': 'csv/crypto_settings.json', 'Forex': 'csv/forex_settings.json', 'Jokes': 'csv/jokes_settings.json',
'Daily Forecast':'csv/daily_weather.json', 'Current Weather': 'csv/current_weather.json', 'Commodities':'csv/commodities_settings.json', 'Indices': 'csv/indices_settings.json',
'Sports (Team Stats)': 'csv/league_tables.json', 'Sports (Past Games)': 'csv/past_games.json', 'IPO Calendar': 'csv/ipo_settings.json', 'Economic Calendar': 'csv/economic_settings.json',
'Sports (Upcoming Games)': 'csv/upcoming_games.json', 'Sports (Live Games)': 'csv/live_games.json', 'Movies': 'csv/movie_settings.json', 'Clock 1': 'csv/clock1_settings.json', 'Clock 2': 'csv/clock2_settings.json', 'World Clock': 'csv/worldclock_settings.json',
'News':'csv/news_settings.json', 'Custom Images': 'csv/image_settings.json', 'Custom GIFs': 'csv/GIF_settings.json', 'Custom Messages': 'csv/message_settings.json', 'Clock 1 Prof': 'csv/clock1_settings.json', 'World Clock Prof': 'csv/worldclock_settings.json',
'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json', 'Jokes Prof': 'csv/jokes_settings.json', 'Clock 2 Prof': 'csv/clock2_settings.json',
'Current Weather Prof': 'csv/current_weather.json', 'News Prof':'csv/news_settings.json', 'Commodities Prof':'csv/commodities_settings.json', 'Indices Prof': 'csv/indices_settings.json',
'Daily Forecast Prof':'csv/daily_weather.json', 'Sports (Team Stats) Prof': 'csv/league_tables.json', 'Sports (Upcoming Games) Prof': 'csv/upcoming_games.json', 'Sports (Past Games) Prof': 'csv/past_games.json', 'Custom Messages Prof': 'csv/message_settings.json', 'Custom Images Prof': 'csv/image_settings.json', 'Movies Prof': 'csv/movie_settings.json', 'Sports (Live Games) Prof': 'csv/live_games.json', 'IPO Calendar Prof': 'csv/ipo_settings.json', 'Economic Calendar Prof': 'csv/economic_settings.json',
'Gainers, Losers, Active':'csv/market_settings.json', 'Gainers, Losers, Active Prof':'csv/market_settings.json', 'Sector Performance':'csv/sector_settings.json', 'Sector Performance Prof':'csv/sector_settings.json', 'Place (Reddit)':'csv/place_settings.json', 'Place (Reddit) Prof':'csv/place_settings.json'}
def openImage(self, image_file):
image = Image.open(image_file)
image = image.convert('RGB')
# Make image fit our screen.
#image.thumbnail((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
#image = image.convert('RGB')
return image
def degreesToCompass(self, deg):
dirs = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
return dirs[int((deg+22.5)//45)%8]
def setImage(self, image, offset_x = 0, offset_y = 0, unsafe=True, min_x = 0, max_x = 128, min_y = 0, max_y = 32):
if (image.mode != "RGB"):
image = image.convert('RGB')
if unsafe:
#In unsafe mode we directly acceshow to send commands to running python processs the underlying PIL image array
#in cython, which is considered unsafe pointer accecss,
#however it's super fast and seems to work fine
#https://groups.google.com/forum/#!topic/cython-users/Dc1ft5W6KM4
img_width, img_height = image.size
self.matrix.SetPixelsPillow(offset_x, offset_y, img_width, img_height, image)
else:
# First implementation of a SetImage(). OPTIMIZE_ME: A more native
# implementation that directly reads the buffer and calls the underlying
# C functions can certainly be faster.
img_width, img_height = image.size
pixels = image.load()
for y in range(max(0, -offset_y), min(img_height, self.matrix.height - offset_y)):
for x in range(max(0, -offset_x), min(img_width, self.matrix.width - offset_x)):
if min_x <= x + offset_x <= max_x and min_y <= y + offset_y <= max_y:
(r, g, b) = pixels[x, y]
self.matrix.SetPixel(x + offset_x, y + offset_y, r*self.brightness, g*self.brightness, b*self.brightness)
def scrollImage(self, image, offset_x = 0, offset_y = 0, frame_skip = 10, gif = False, pause_frames = 0, place = False):
img_width, img_height = image.size
kill = False
if place:
value = -85
else:
value = 0
while offset_x > -(img_width+1):
if offset_x == value:
while pause_frames > 0:
if pause_frames%frame_skip == 0:
self.incrementGIF(image)
pause_frames -=1
if gif:
self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y)
else:
self.double_buffer.SetImage(image, offset_x, offset_y)
for y in range(self.matrix.height):
self.matrix.SetPixel(offset_x + img_width +1 , y , 0,0,0)
self.matrix.SetPixel(offset_x + img_width , y , 0,0,0)
self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer)
time.sleep(self.delay)
kill = self.checkKilled()
if kill: break
if kill: break
# for animation in gifs
if offset_x%frame_skip == 0:
self.incrementGIF(image)
#image = image.convert('RGB')
offset_x -= 1
#self.setImage(image.convert('RGB'), offset_x = offset_x, offset_y = offset_y)
if gif:
self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y)
else:
self.double_buffer.SetImage(image, offset_x, offset_y)
buff = 0
# remove the ppixels behind the image, to stop trailing
self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer)
for y in range(self.matrix.height):
self.matrix.SetPixel(offset_x + img_width +1 , y , 0,0,0)
self.matrix.SetPixel(offset_x + img_width , y , 0,0,0)
time.sleep(self.delay)
kill = self.checkKilled()
if kill: break
return kill
def scrollImageY(self, image, direction = 1, offset_x = 0, offset_y = 0, frame_skip = 10, gif = False):
kill = False
while offset_y != 0:
# for animation in gifs
if offset_y%frame_skip == 0:
self.incrementGIF(image)
offset_y += direction
if gif:
self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y)
else:
self.double_buffer.SetImage(image, offset_x, offset_y)
self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer)
time.sleep(self.delay)
kill = self.checkKilled()
if kill: break
return kill
def scrollImageTransition(self, image_files, offset_x = 0, offset_y = 0, stocks = True):
# use two image files and switch between them with a seemless transition
current_img = 1
image1 = self.openImage(image_files[0]).convert('RGB')
image2 = self.openImage(image_files[1]).convert('RGB')
double_buffer = self.matrix.CreateFrameCanvas()
kill = False
while True:
if current_img == 1:
if stocks:
update_process = Process(target = self.getFullStockImage, args = (1,))
update_process.start()
image1 = self.openImage(image_files[0]).convert('RGB')
image2 = self.openImage(image_files[1]).convert('RGB')
elif current_img == 2:
if stocks:
update_process = Process(target = self.getFullStockImage, args = (2,))
update_process.start()
image1 = self.openImage(image_files[1]).convert('RGB')
image2 = self.openImage(image_files[0]).convert('RGB')
img_width, img_height = image1.size
while offset_x > -img_width:
offset_x -= 1
double_buffer.SetImage(image1, offset_x, offset_y)
if offset_x + img_width < self.matrix.width: # if the image is ending
double_buffer.SetImage(image2, offset_x, offset_y)
double_buffer = self.matrix.SwapOnVSync(double_buffer)
time.sleep(self.delay)
kill = self.checkKilled()
if kill: break
if stocks:
image1.close()
image2.close()
if kill: break
if stocks:
update_process.join()
update_process.terminate()
if current_img == 1:
current_img = 2
elif current_img == 2:
current_img = 1
offset_x = 0
update_process.join()
update_process.terminate()
def scrollImageStacked(self, image, offset_x = 0, offset_y = 0):
img_width, img_height = image.size
while offset_x > -img_width - 128:
offset_x -= 1
self.setImage(image, offset_x = offset_x+128, offset_y = offset_y)
self.setImage(image, offset_x = offset_x, offset_y = offset_y+20)
kill = self.checkKilled()
time.sleep(self.delay)
return kill
def updateMultiple(self, options):
for option in options:
if option not in ['Custom GIFs', 'Custom Images', 'Custom Messages', 'Place (Reddit)', 'Clock 1', 'Clock 2', 'World Clock', 'Clock 1 Prof', 'Clock 2 Prof', 'World Clock Prof']: # these images are already saved in user uploads, dodnt need to update them
img = self.functions[option]()
img.save('./display_images/'+ option+ '.ppm')
def incrementGIF(self, image):
try:
image.seek(self.frame)
except EOFError:
self.frame = 0
image.seek(self.frame)
self.frame +=1
def checkKilled(self):
kill = False
try:
msg = getInput()
if msg == 'K':
self.resetMatrix()
kill = True
self.process_msg(msg)
except KeyboardInterrupt:
sys.stdout.flush()
pass
return kill
def set_delay(self,speed):
if speed.lower() == 'slow':
self.delay = 0.03
elif speed.lower() == 'medium':
self.delay = 0.02
elif speed.lower() == 'fast':
self.delay = 0.01
return self.delay
def scrollFunctionsAnimated(self, options, animation = 'down', repeat = True):
# scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed
self.updateMultiple([options[0]])
kill = False
i = 0 # keep track of which image we are displaying
self.double_buffer = self.matrix.CreateFrameCanvas()
while True:
update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],))
update_process.start()
f = open(self.JSONs[options[(i) % len(options)]])
settings = json.load(f)
f.close()
if options[i % len(options)] == 'Clock 1':
kill=self.showClock1()
elif options[i % len(options)] == 'Clock 2':
kill=self.showClock2()
elif options[i % len(options)] == 'World Clock':
kill=self.showWorldclock()
else:
self.set_delay(settings['speed'])
animation = settings['animation'].lower()
if options[i % len(options)] == 'Custom Images':
images = self.getUserImages()
elif options[i % len(options)] == 'Place (Reddit)':
images = self.getPlaceImage()
elif options[i % len(options)] == 'Custom GIFs':
images = self.getUserGIFs()
elif options[i % len(options)] == 'Custom Messages':
images = self.getUserMessages()
else: #these options just have a single ppm image
image = self.openImage('./display_images/' + options[i % len(options)] +'.ppm')
images = [image]
for image in images:
img_width, img_height = image.size
offset_x = 0
if animation == 'continuous':
offset_x = 128
elif animation in ['up', 'down']:
offset_x = max(0, 128-img_width)
offset_y = 0
#first scroll image in from bottom
frame_skip = int((1/15)/self.delay) #controls how fast gifs run
self.frame = 0
pause_frames = int(0.5/self.delay)
if animation == 'up':
offset_y = 33
direction = -1
kill = self.scrollImageY(image, direction = direction, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] == 'Custom GIFs')
elif animation == 'down':
direction = 1
offset_y = -33
kill = self.scrollImageY(image, direction = direction, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] == 'Custom GIFs')
if kill: break
offset_y = 0
if animation in ['up', 'down']:
while pause_frames > 0:
if pause_frames%frame_skip == 0:
self.incrementGIF(image)
pause_frames -=1
if options[i % len(options)] != 'Custom GIFs':
self.double_buffer.SetImage(image, offset_x, offset_y)
else:
self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y)
self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer)
time.sleep(self.delay)
kill = self.checkKilled()
if kill: break
if kill: break
if kill: break
try:
pause = float(settings['pause'])
except:
pause = 0
pause_frames = int(float(pause)/self.delay)
if options[i % len(options)] == 'Place (Reddit)':
global place_featuretitle
place_true = place_featuretitle
else:
place_true = False
kill = self.scrollImage(image, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] == 'Custom GIFs', pause_frames = pause_frames, place = place_true)
if kill: break
if kill:break
if not repeat:
break
update_process.join()
update_process.terminate()
i+=1
def scrollProfessionalAnimated(self, options, animation = 'on'):
# scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed
top = options[0]
bottom = options[1]
# self.updateMultiple([top[0], bottom[0]])
# ADDING THIS FOR COLORS FOR CLOCK FEATURES
time_colors1 = {
"White": (255,255,255), "Red": (255, 0,0), "Green": (0,255,0), "Dark Green": (0, 100,0), "Blue": (0,0,255), "Purple": (145,0,255),
"Pink": (255,0,255), "Yellow": (255,255,0), "Orange": (255,130,0), "Gold": (255,190,0), "Gray": (100,100,100), "Cyan": (0,255,255)}
day_colors = {"day":(255, 191, 0), "night":(0, 71,171)}
def isDaytime1(time,twelvehours):
if twelvehours:
hour = int(time.split(':')[0])
daytime_start_hour = 6
daytime_end_hour = 6
am_pm = time[-2:]
if (6 <= hour <= 11 and am_pm == 'AM') or (1 <= hour <= 6 and am_pm == 'PM') or (hour == 12 and am_pm == 'PM'):
return True
else:
return False
else:
hour = time.split(':')[0]
daytime_start_hour = 6
daytime_end_hour = 18
if daytime_start_hour <= int(hour) <= daytime_end_hour:
return True
else:
return False
kill = False
i1 = 0 # keep track of which image we are displaying
i2 = 0 # keep track of which image we are displaying
self.double_buffer = self.matrix.CreateFrameCanvas()
update_process = Process(target = self.updateMultiple, args = ([top[(i1+1) % len(top)]+ ' Prof', bottom[(i2+1) % len(bottom)]+ ' Prof' ],))
update_process.start()
self.updateMultiple([top[i1 % len(top)]+ ' Prof', bottom[i2 % len(bottom)]+ ' Prof' ])
settings1 = json.load(open(self.JSONs[top[i1 % len(top)]]))
settings2 = json.load(open(self.JSONs[bottom[i2 % len(bottom)] ]))
if 'Clock' not in top[i1 % len(top)]:
image1 = self.openImage('./display_images/' + top[i1 % len(top)] +' Prof.ppm')
image1 = image1.convert('RGB')
elif top[i1 % len(top)] == 'Clock 2': #CLOCK 2 SETTINGS
image1 = Image.new('RGB', (128, 16))
draw = ImageDraw.Draw(image1)
the_time = time.time()
font = ImageFont.load("fonts/6x12.pil")
font2 = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock2_settings = json.load(f)['clock2']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock2_settings = clock_settings['clock2']
time_color1 = clock2_settings['time_color']
date_color1 = clock2_settings['date_color']
timezone1 = clock2_settings['timezone']
display_s = clock2_settings['display_seconds']
display_p = clock2_settings['display_pm']
twelvehours = clock2_settings['12hour']
if twelvehours:
if display_p and display_s:
time_format = "%I:%M:%S %p"
elif display_p and not display_s:
time_format = "%I:%M %p"
elif not display_p and display_s:
time_format = "%I:%M:%S"
else:
time_format = "%I:%M"
else:
if display_p and display_s:
time_format = "%H:%M:%S %p"
elif display_p and not display_s:
time_format = "%H:%M %p"
elif not display_p and display_s:
time_format = "%H:%M:%S"
else:
time_format = "%H:%M"
if '+' in timezone1:
timezone1 = timezone1.replace('+', '-')
elif '-' in timezone1:
timezone1 = timezone1.replace('-', '+')
elif top[i1 % len(top)] == 'Clock 1': #CLOCK 1 SETTINGS
image1 = Image.new('RGB', (128, 16))
draw = ImageDraw.Draw(image1)
the_time = time.time()
font_1 = ImageFont.load("fonts/7x14B.pil")
font_2 = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock1_settings = json.load(f)['clock1']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock1_settings = clock_settings['clock1']
time_color2 = clock1_settings['time_color']
date_color2 = clock1_settings['date_color']
weekday_color2 = clock1_settings['weekday_color']
timezone2 = clock1_settings['timezone']
display_s = clock1_settings['display_seconds']
display_p = clock1_settings['display_pm']
twelvehours = clock1_settings['12hour']
if twelvehours:
if display_p and display_s:
time_format = "%I:%M:%S %p"
elif display_p and not display_s:
time_format = "%I:%M %p"
elif not display_p and display_s:
time_format = "%I:%M:%S"
else:
time_format = "%I:%M"
else:
if display_p and display_s:
time_format = "%H:%M:%S %p"
elif display_p and not display_s:
time_format = "%H:%M %p"
elif not display_p and display_s:
time_format = "%H:%M:%S"
else:
time_format = "%H:%M"
if '+' in timezone2:
timezone2 = timezone2.replace('+', '-')
elif '-' in timezone2:
timezone2 = timezone2.replace('-', '+')
elif top[i1 % len(top)] == 'World Clock': #WORLD CLOCK SETTINGS
image1 = Image.new('RGB', (128, 16))
draw = ImageDraw.Draw(image1)
the_time = time.time()
next_six_seconds = 0
counter = 0
font_1 = ImageFont.load("fonts/4x6.pil")
try:
with open('clock_screensaver.json', 'r') as f:
world_settings = json.load(f)['world_clock']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
world_settings = clock_settings['world_clock']
worldcity_color = world_settings['city_color']
display_s = world_settings['display_seconds']
display_p = world_settings['display_pm']
twelvehours = world_settings['12hour']
if twelvehours:
if display_p and display_s:
time_format = "%I:%M:%S %p"
world_offset = 82
elif display_p and not display_s:
time_format = "%I:%M %p"
world_offset = 94
elif not display_p and display_s:
time_format = "%I:%M:%S %p"
world_offset = 94
else:
time_format = "%I:%M %p"
world_offset = 106
else:
if display_p and display_s:
time_format = "%H:%M:%S %p"
world_offset = 82
elif display_p and not display_s:
time_format = "%H:%M %p"
world_offset = 94
elif not display_p and display_s:
time_format = "%H:%M:%S %p"
world_offset = 94
else:
time_format = "%H:%M %p"
world_offset = 106
#BOTTOM SETTINGS
if 'Clock' not in bottom[i2 % len(bottom)]:
image2 = self.openImage('./display_images/' + bottom[i2 % len(bottom)] +' Prof.ppm')
image2 = image2.convert('RGB')
elif bottom[i2 % len(bottom)] == 'Clock 2': #CLOCK 2 SETTINGS
image2 = Image.new('RGB', (128, 16))
draw2 = ImageDraw.Draw(image2)
the_time2 = time.time()
font_b = ImageFont.load("fonts/6x12.pil")
font2_b = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock2_settings = json.load(f)['clock2']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock2_settings = clock_settings['clock2']
time_color1_b = clock2_settings['time_color']
date_color1_b = clock2_settings['date_color']
timezone1_b = clock2_settings['timezone']
display_s_b = clock2_settings['display_seconds']
display_p_b = clock2_settings['display_pm']
twelvehours_b = clock2_settings['12hour']
if twelvehours_b:
if display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%I:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%I:%M:%S"
else:
time_format_b = "%I:%M"
else:
if display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%H:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%H:%M:%S"
else:
time_format_b = "%H:%M"
if '+' in timezone1_b:
timezone1_b = timezone1_b.replace('+', '-')
elif '-' in timezone1_b:
timezone1_b = timezone1_b.replace('-', '+')
elif bottom[i2 % len(bottom)] == 'Clock 1': #CLOCK 1 SETTINGS
image2 = Image.new('RGB', (128, 16))
draw2 = ImageDraw.Draw(image2)
the_time2 = time.time()
font_1_b = ImageFont.load("fonts/7x14B.pil")
font_2_b = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock1_settings = json.load(f)['clock1']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock1_settings = clock_settings['clock1']
time_color2_b = clock1_settings['time_color']
date_color2_b = clock1_settings['date_color']
weekday_color2_b = clock1_settings['weekday_color']
timezone2_b = clock1_settings['timezone']
display_s_b = clock1_settings['display_seconds']
display_p_b = clock1_settings['display_pm']
twelvehours_b = clock1_settings['12hour']
if twelvehours_b:
if display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%I:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%I:%M:%S"
else:
time_format_b = "%I:%M"
else:
if display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%H:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%H:%M:%S"
else:
time_format_b = "%H:%M"
if '+' in timezone2_b:
timezone2_b = timezone2_b.replace('+', '-')
elif '-' in timezone2_b:
timezone2_b = timezone2_b.replace('-', '+')
elif bottom[i2 % len(bottom)] == 'World Clock': #WORLD CLOCK SETTINGS
image2 = Image.new('RGB', (128, 16))
draw2 = ImageDraw.Draw(image2)
the_time2 = time.time()
next_six_seconds2 = 0
counter2 = 0
font_12 = ImageFont.load("fonts/4x6.pil")
try:
with open('clock_screensaver.json', 'r') as f:
world_settings = json.load(f)['world_clock']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
world_settings = clock_settings['world_clock']
worldcity_color2 = world_settings['city_color']
display_s_b = world_settings['display_seconds']
display_p_b = world_settings['display_pm']
twelvehours_b = world_settings['12hour']
if twelvehours_b:
if display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
world_offset_b = 82
elif display_p_b and not display_s_b:
time_format_b = "%I:%M %p"
world_offset_b = 94
elif not display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
world_offset_b = 94
else:
time_format_b = "%I:%M %p"
world_offset_b = 106
else:
if display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
world_offset_b = 82
elif display_p_b and not display_s_b:
time_format_b = "%H:%M %p"
world_offset_b = 94
elif not display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
world_offset_b = 94
else:
time_format_b = "%H:%M %p"
world_offset_b = 106
delay_t1 = self.set_delay(settings1['speed'])
try:
animation1 = settings1['animation'].lower()
except:
animation1 = settings1['transition'].lower()
try:
delay_t2 = self.set_delay(settings2['speed2'])
except:
delay_t2 = self.set_delay(settings2['speed'])
try:
animation2 = settings2['animation'].lower()
except:
animation2 = settings2['transition'].lower()
try:
pause1 = int(settings1['pause'])
except:
pause1 = 0
try:
pause2 = int(settings2['pause'])
except:
pause2 = 0
if animation1 == 'continuous':
offset_y1 = 0
offset_x1 = 128
else:
offset_y1 = -16
offset_x1 = 0
if animation2 == 'continuous':
offset_y2 = 16
offset_x2 = 128
else:
offset_y2 = 32
offset_x2 = 0
# frame_skip = int((1/15)/self.delay) #controls how fast gifs run
# self.frame = 0
img_width1, img_height1 = image1.size
img_width2, img_height2 = image2.size
kill = False
update_t1 = time.time()
update_t2 = time.time()
while True:
# UPDATE IMAGE 1 WHEN PRIOR FEATURE DONE DISPLAYING
if offset_x1 < -(img_width1+1):
i1 += 1
settings1 = json.load(open(self.JSONs[top[i1 % len(top)]]))
delay_t1 = self.set_delay(settings1['speed'])
try:
animation1 = settings1['animation'].lower()
except:
animation1 = settings1['transition'].lower()
try:
pause1 = int(settings1['pause'])
except:
pause1 = 0
if animation1 == 'continuous':
offset_y1 = 0
offset_x1 = 128
else:
offset_y1 = -16
offset_x1 = 0
update_process.join()
update_process.terminate()
update_process = Process(target = self.updateMultiple, args = ([top[(i1+1) % len(top)]+ ' Prof'],))
update_process.start()
if 'Clock' not in top[i1 % len(top)]:
image1 = self.openImage('./display_images/' + top[i1 % len(top)] +' Prof.ppm')
image1 = image1.convert('RGB')
elif top[i1 % len(top)] == 'Clock 2': #CLOCK2 SETTINGS
image1 = Image.new('RGB', (128, 16))
draw = ImageDraw.Draw(image1)
the_time = time.time()
font = ImageFont.load("fonts/6x12.pil")
font2 = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock2_settings = json.load(f)['clock2']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock2_settings = clock_settings['clock2']
time_color1 = clock2_settings['time_color']
date_color1 = clock2_settings['date_color']
timezone1 = clock2_settings['timezone']
display_s = clock2_settings['display_seconds']
display_p = clock2_settings['display_pm']
twelvehours = clock2_settings['12hour']
if twelvehours:
if display_p and display_s:
time_format = "%I:%M:%S %p"
elif display_p and not display_s:
time_format = "%I:%M %p"
elif not display_p and display_s:
time_format = "%I:%M:%S"
else:
time_format = "%I:%M"
else:
if display_p and display_s:
time_format = "%H:%M:%S %p"
elif display_p and not display_s:
time_format = "%H:%M %p"
elif not display_p and display_s:
time_format = "%H:%M:%S"
else:
time_format = "%H:%M"
if '+' in timezone1:
timezone1 = timezone1.replace('+', '-')
elif '-' in timezone1:
timezone1 = timezone1.replace('-', '+')
elif top[i1 % len(top)] == 'Clock 1': #CLOCK 1 SETTINGS
image1 = Image.new('RGB', (128, 16))
draw = ImageDraw.Draw(image1)
the_time = time.time()
font_1 = ImageFont.load("fonts/7x14B.pil")
font_2 = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock1_settings = json.load(f)['clock1']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock1_settings = clock_settings['clock1']
time_color2 = clock1_settings['time_color']
date_color2 = clock1_settings['date_color']
weekday_color2 = clock1_settings['weekday_color']
timezone2 = clock1_settings['timezone']
display_s = clock1_settings['display_seconds']
display_p = clock1_settings['display_pm']
twelvehours = clock1_settings['12hour']
if twelvehours:
if display_p and display_s:
time_format = "%I:%M:%S %p"
elif display_p and not display_s:
time_format = "%I:%M %p"
elif not display_p and display_s:
time_format = "%I:%M:%S"
else:
time_format = "%I:%M"
else:
if display_p and display_s:
time_format = "%H:%M:%S %p"
elif display_p and not display_s:
time_format = "%H:%M %p"
elif not display_p and display_s:
time_format = "%H:%M:%S"
else:
time_format = "%H:%M"
if '+' in timezone2:
timezone2 = timezone2.replace('+', '-')
elif '-' in timezone2:
timezone2 = timezone2.replace('-', '+')
elif top[i1 % len(top)] == 'World Clock': #WORLD CLOCK SETTINGS
image1 = Image.new('RGB', (128, 16))
draw = ImageDraw.Draw(image1)
the_time = time.time()
next_six_seconds = 0
counter = 0
font_1 = ImageFont.load("fonts/4x6.pil")
try:
with open('clock_screensaver.json', 'r') as f:
world_settings = json.load(f)['world_clock']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
world_settings = clock_settings['world_clock']
worldcity_color = world_settings['city_color']
display_s = world_settings['display_seconds']
display_p = world_settings['display_pm']
twelvehours = world_settings['12hour']
if twelvehours:
if display_p and display_s:
time_format = "%I:%M:%S %p"
world_offset = 82
elif display_p and not display_s:
time_format = "%I:%M %p"
world_offset = 94
elif not display_p and display_s:
time_format = "%I:%M:%S %p"
world_offset = 94
else:
time_format = "%I:%M %p"
world_offset = 106
else:
if display_p and display_s:
time_format = "%H:%M:%S %p"
world_offset = 82
elif display_p and not display_s:
time_format = "%H:%M %p"
world_offset = 94
elif not display_p and display_s:
time_format = "%H:%M:%S %p"
world_offset = 94
else:
time_format = "%H:%M %p"
world_offset = 106
img_width1, img_height1 = image1.size
# UPDATE IMAGE 2 WHEN PRIOR FEATURE DONE DISPLAYING
if offset_x2 < -(img_width2+1):
i2 += 1
settings2 = json.load(open(self.JSONs[bottom[(i2) % len(bottom)]]))
try:
delay_t2 = self.set_delay(settings2['speed2'])
except:
delay_t2 = self.set_delay(settings2['speed'])
try:
animation2 = settings2['animation'].lower()
except:
animation2 = settings2['transition'].lower()
try:
pause2 = int(settings2['pause'])
except:
pause2 = 0
if animation2 == 'continuous':
offset_y2 = 16
offset_x2 = 128
else:
offset_y2 = 32
offset_x2 = 0
update_process.join()
update_process.terminate()
update_process = Process(target = self.updateMultiple, args = ([bottom[i2 % len(bottom)]+ ' Prof'],))
update_process.start()
if 'Clock' not in bottom[i2 % len(bottom)]:
image2 = self.openImage('./display_images/' + bottom[i2 % len(bottom)] +' Prof.ppm')
image2 = image2.convert('RGB')
elif bottom[i2 % len(bottom)] == 'Clock 2': #CLOCK 2 SETTINGS
image2 = Image.new('RGB', (128, 16))
draw2 = ImageDraw.Draw(image2)
the_time2 = time.time()
font_b = ImageFont.load("fonts/6x12.pil")
font2_b = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock2_settings = json.load(f)['clock2']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock2_settings = clock_settings['clock2']
time_color1_b = clock2_settings['time_color']
date_color1_b = clock2_settings['date_color']
timezone1_b = clock2_settings['timezone']
display_s_b = clock2_settings['display_seconds']
display_p_b = clock2_settings['display_pm']
twelvehours_b = clock2_settings['12hour']
if twelvehours_b:
if display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%I:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%I:%M:%S"
else:
time_format_b = "%I:%M"
else:
if display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%H:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%H:%M:%S"
else:
time_format_b = "%H:%M"
if '+' in timezone1_b:
timezone1_b = timezone1_b.replace('+', '-')
elif '-' in timezone1_b:
timezone1_b = timezone1_b.replace('-', '+')
elif bottom[i2 % len(bottom)] == 'Clock 1': #CLOCK 1 SETTINGS
image2 = Image.new('RGB', (128, 16))
draw2 = ImageDraw.Draw(image2)
the_time2 = time.time()
font_1_b = ImageFont.load("fonts/7x14B.pil")
font_2_b = ImageFont.load("fonts/5x8.pil")
try:
with open('clock_screensaver.json', 'r') as f:
clock1_settings = json.load(f)['clock1']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
clock1_settings = clock_settings['clock1']
time_color2_b = clock1_settings['time_color']
date_color2_b = clock1_settings['date_color']
weekday_color2_b = clock1_settings['weekday_color']
timezone2_b = clock1_settings['timezone']
display_s_b = clock1_settings['display_seconds']
display_p_b = clock1_settings['display_pm']
twelvehours_b = clock1_settings['12hour']
if twelvehours_b:
if display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%I:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%I:%M:%S"
else:
time_format_b = "%I:%M"
else:
if display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
elif display_p_b and not display_s_b:
time_format_b = "%H:%M %p"
elif not display_p_b and display_s_b:
time_format_b = "%H:%M:%S"
else:
time_format_b = "%H:%M"
if '+' in timezone2_b:
timezone2_b = timezone2_b.replace('+', '-')
elif '-' in timezone2_b:
timezone2_b = timezone2_b.replace('-', '+')
elif bottom[i2 % len(bottom)] == 'World Clock': #WORLD CLOCK SETTINGS
image2 = Image.new('RGB', (128, 16))
draw2 = ImageDraw.Draw(image2)
the_time2 = time.time()
next_six_seconds2 = 0
counter2 = 0
font_12 = ImageFont.load("fonts/4x6.pil")
try:
with open('clock_screensaver.json', 'r') as f:
world_settings = json.load(f)['world_clock']
except:
clock_settings = {"clock1": {"time_color": "White", "weekday_color": "Cyan", "date_color": "Blue", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "clock2": {"time_color": "Orange", "date_color": "White", "timezone": "Etc/GMT+4", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}, "world_clock": {"city_color": "White", "display_seconds": True, "display_pm": True, "12hour": True, "brightness": "10"}}
with open('clock_screensaver.json', 'w') as f:
json.dump(clock_settings, f)
world_settings = clock_settings['world_clock']
worldcity_color2 = world_settings['city_color']
display_s_b = world_settings['display_seconds']
display_p_b = world_settings['display_pm']
twelvehours_b = world_settings['12hour']
if twelvehours_b:
if display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
world_offset_b = 82
elif display_p_b and not display_s_b:
time_format_b = "%I:%M %p"
world_offset_b = 94
elif not display_p_b and display_s_b:
time_format_b = "%I:%M:%S %p"
world_offset_b = 94
else:
time_format_b = "%I:%M %p"
world_offset_b = 106
else:
if display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
world_offset_b = 82
elif display_p_b and not display_s_b:
time_format_b = "%H:%M %p"
world_offset_b = 94
elif not display_p_b and display_s_b:
time_format_b = "%H:%M:%S %p"
world_offset_b = 94
else:
time_format_b = "%H:%M %p"
world_offset_b = 106
img_width2, img_height2 = image2.size
# SCROLL, DISPLAY, PAUSE CLOCK 2
if top[i1 % len(top)] == 'Clock 2':
#Initial image generation so it doesn't appear blank for the first second
if offset_x1 == 128 or offset_y1 == -16:
draw.rectangle([(0,0),(128,16)], (0,0,0))
current_time = datetime.now(pytz.timezone(timezone1)).strftime(time_format + ",%a %d %b %Y").split(',')
time_t = current_time[0]
date_t = current_time[1].upper()
date_width, date_height = draw.textsize(date_t, font2)
text_width, text_height = draw.textsize(time_t, font)
draw.text(((128-text_width)/2, -2), time_t, time_colors1[time_color1], font)
draw.text(((128-date_width)/2, 8), date_t, time_colors1[date_color1], font2)
#If time now is greater than 1 second of the previously updated image time, update image and reset updated image time to another second
if time.time() >= the_time + 1:
the_time = time.time()
draw.rectangle([(0,0),(128,16)], (0,0,0))
current_time = datetime.now(pytz.timezone(timezone1)).strftime(time_format + ",%a %d %b %Y").split(',')
time_t = current_time[0]
date_t = current_time[1].upper()
date_width, date_height = draw.textsize(date_t, font2)
text_width, text_height = draw.textsize(time_t, font)
draw.text(((128-text_width)/2, -2), time_t, time_colors1[time_color1], font)
draw.text(((128-date_width)/2, 8), date_t, time_colors1[date_color1], font2)
if time.time() - update_t1 > delay_t1:
update_t1 = time.time()
#Get the pause time right before image is done transitioning in
if offset_y1 == -1 or offset_x1 == 1:
pause_time = time.time() + pause1
if offset_y1 < 0:
offset_y1+=1
else: #If the scrolling reaches 0 pixel, pause it
if offset_x1 != 0:
offset_x1 -= 1
else:
try: #after the pause time, scroll iamge past 0 pixel to continue scrolling
if time.time() >= pause_time:
offset_x1 -= 1
except:
pass
# SCROLL, DISPLAY, PAUSE CLOCK 1
elif top[i1 % len(top)] == 'Clock 1':
#Initial image generation so it doesn't appear blank for the first second
if offset_x1 == 128 or offset_y1 == -16:
draw.rectangle([(0,0),(128,16)], (0,0,0))
current_time = datetime.now(pytz.timezone(timezone2)).strftime(time_format + ",%A,%d %b").split(',')
time_t = current_time[0]
weekday_t = current_time[1].upper()
date_t = current_time[2].upper()
date_width, date_height = draw.textsize(date_t, font_2)
wday_width, wday_height = draw.textsize(weekday_t, font_2)
text_width, text_height = draw.textsize(time_t, font_1)
total_width = text_width + 5 + max(wday_width, date_width)
starting_coord = (128-total_width)/2
draw.text((starting_coord, 1), time_t, time_colors1[time_color2], font_1)
draw.text((starting_coord + text_width + 5, 1), date_t, time_colors1[date_color2], font_2)
draw.text((starting_coord + text_width + 6, 8), weekday_t, time_colors1[weekday_color2], font_2)
#If time now is greater than 1 second of the previously updated image time, update image and reset updated image time to another second
if time.time() >= the_time + 1:
the_time = time.time()
draw.rectangle([(0,0),(128,16)], (0,0,0))
current_time = datetime.now(pytz.timezone(timezone2)).strftime(time_format + ",%A,%d %b").split(',')
time_t = current_time[0]
weekday_t = current_time[1].upper()
date_t = current_time[2].upper()
date_width, date_height = draw.textsize(date_t, font_2)
wday_width, wday_height = draw.textsize(weekday_t, font_2)
text_width, text_height = draw.textsize(time_t, font_1)
total_width = text_width + 5 + max(wday_width, date_width)
starting_coord = (128-total_width)/2
draw.text((starting_coord, 1), time_t, time_colors1[time_color2], font_1)
draw.text((starting_coord + text_width + 5, 1), date_t, time_colors1[date_color2], font_2)
draw.text((starting_coord + text_width + 6, 8), weekday_t, time_colors1[weekday_color2], font_2)
if time.time() - update_t1 > delay_t1:
update_t1 = time.time()
#Get the pause time right before image is done transitioning in
if offset_y1 == -1 or offset_x1 == 1:
pause_time = time.time() + pause1
if offset_y1 < 0:
offset_y1+=1
else: #If the scrolling reaches 0 pixel, pause it
if offset_x1 != 0:
offset_x1 -= 1
else:
try: #after the pause time, scroll iamge past 0 pixel to continue scrolling
if time.time() >= pause_time:
offset_x1 -= 1
except:
pass
# SCROLL, DISPLAY, PAUSE WORLD CLOCK
elif top[i1 % len(top)] == 'World Clock':
#Initial image generation so it doesn't appear blank for the first second
if offset_x1 == 128 or offset_y1 == -16:
draw.rectangle([(0,0),(128,16)], (0,0,0))
ny_time = datetime.now(pytz.timezone('America/New_York')).strftime(time_format)
london_time = datetime.now(pytz.timezone('Europe/London')).strftime(time_format)
ny_color = day_colors['day'] if isDaytime1(ny_time,twelvehours) else day_colors['night']
london_color = day_colors['day'] if isDaytime1(london_time,twelvehours) else day_colors['night']
if not display_p:
ny_time = ny_time.replace("PM", "").replace("AM", "")
london_time = london_time.replace("PM", "").replace("AM", "")
draw.text((world_offset, 1), ny_time, ny_color, font_1)
draw.text((world_offset, 9), london_time, london_color, font_1)
draw.line([0,7,128,7],(50,50,50), width=1)
draw.text((3, 1), 'NEW YORK', time_colors1[worldcity_color], font_1)
draw.text((3, 9), 'LONDON', time_colors1[worldcity_color], font_1)
#If time now is greater than 1 second of the previously updated image time, update image and reset updated image time to another second
if time.time() >= the_time + 1:
the_time = time.time()
if counter == 0 or counter == 1:
draw.rectangle([(0,0),(128,16)], (0,0,0))
ny_time = datetime.now(pytz.timezone('America/New_York')).strftime(time_format)
london_time = datetime.now(pytz.timezone('Europe/London')).strftime(time_format)
ny_color = day_colors['day'] if isDaytime1(ny_time,twelvehours) else day_colors['night']
london_color = day_colors['day'] if isDaytime1(london_time,twelvehours) else day_colors['night']
if not display_p:
ny_time = ny_time.replace("PM", "").replace("AM", "")
london_time = london_time.replace("PM", "").replace("AM", "")
draw.text((world_offset, 1), ny_time, ny_color, font_1)
draw.text((world_offset, 9), london_time, london_color, font_1)
draw.line([0,7,128,7],(50,50,50), width=1)
draw.text((3, 1), 'NEW YORK', time_colors1[worldcity_color], font_1)
draw.text((3, 9), 'LONDON', time_colors1[worldcity_color], font_1)
elif counter == 2:
draw.rectangle([(0,0),(128,16)], (0,0,0))
tokyo_time = datetime.now(pytz.timezone('Asia/Tokyo')).strftime(time_format)
au_time = datetime.now(pytz.timezone('Australia/Sydney')).strftime(time_format)
tokyo_color = day_colors['day'] if isDaytime1(tokyo_time,twelvehours) else day_colors['night']
au_color = day_colors['day'] if isDaytime1(au_time,twelvehours) else day_colors['night']
if not display_p:
au_time = au_time.replace("PM", "").replace("AM", "")
tokyo_time = tokyo_time.replace("PM", "").replace("AM", "")
draw.text((world_offset, 1), tokyo_time, tokyo_color, font_1)
draw.text((world_offset, 9), au_time, au_color, font_1)
draw.line([0,7,128,7],(50,50,50), width=1)
draw.text((3, 1), 'TOKYO', time_colors1[worldcity_color], font_1)
draw.text((3, 9), 'SYDNEY', time_colors1[worldcity_color], font_1)
elif counter == 3:
draw.rectangle([(0,0),(128,16)], (0,0,0))
dubai_time = datetime.now(pytz.timezone('Asia/Dubai')).strftime(time_format)
la_time = datetime.now(pytz.timezone('America/Los_Angeles')).strftime(time_format)
dubai_color = day_colors['day'] if isDaytime1(dubai_time,twelvehours) else day_colors['night']
la_color = day_colors['day'] if isDaytime1(la_time,twelvehours) else day_colors['night']
if not display_p:
dubai_time = dubai_time.replace("PM", "").replace("AM", "")
la_time = la_time.replace("PM", "").replace("AM", "")
draw.text((world_offset, 1), dubai_time, dubai_color, font_1)
draw.text((world_offset, 9), la_time, la_color, font_1)
draw.line([0,7,128,7],(50,50,50), width=1)
draw.text((3, 1), 'DUBAI', time_colors1[worldcity_color], font_1)
draw.text((3, 9), 'LOS ANGELES', time_colors1[worldcity_color], font_1)
elif counter == 4:
draw.rectangle([(0,0),(128,16)], (0,0,0))
cn_time = datetime.now(pytz.timezone('Asia/Shanghai')).strftime(time_format)
paris_time = datetime.now(pytz.timezone('Europe/Paris')).strftime(time_format)
cn_color = day_colors['day'] if isDaytime1(cn_time,twelvehours) else day_colors['night']
paris_color = day_colors['day'] if isDaytime1(paris_time,twelvehours) else day_colors['night']
if not display_p:
cn_time = cn_time.replace("PM", "").replace("AM", "")
paris_time = paris_time.replace("PM", "").replace("AM", "")
draw.text((world_offset, 1), cn_time, cn_color, font_1)
draw.text((world_offset, 9), paris_time, paris_color, font_1)
draw.line([0,7,128,7],(50,50,50), width=1)
draw.text((3, 1), 'SHANGHAI', time_colors1[worldcity_color], font_1)
draw.text((3, 9), 'PARIS', time_colors1[worldcity_color], font_1)
elif counter == 5:
draw.rectangle([(0,0),(128,16)], (0,0,0))
in_time = datetime.now(pytz.timezone('Asia/Kolkata')).strftime(time_format)
auck_time = datetime.now(pytz.timezone('Pacific/Auckland')).strftime(time_format)
in_color = day_colors['day'] if isDaytime1(in_time,twelvehours) else day_colors['night']
auck_color = day_colors['day'] if isDaytime1(auck_time,twelvehours) else day_colors['night']
if not display_p:
in_time = in_time.replace("PM", "").replace("AM", "")
auck_time = auck_time.replace("PM", "").replace("AM", "")
draw.text((world_offset, 1), in_time, in_color, font_1)
draw.text((world_offset, 9), auck_time, auck_color, font_1)
draw.line([0,7,128,7],(50,50,50), width=1)
draw.text((3, 1), 'MUMBAI', time_colors1[worldcity_color], font_1)
draw.text((3, 9), 'AUCKLAND', time_colors1[worldcity_color], font_1)
elif counter == 6:
draw.rectangle([(0,0),(128,16)], (0,0,0))
bang_time = datetime.now(pytz.timezone('Asia/Bangkok')).strftime(time_format)
istan_time = datetime.now(pytz.timezone('Europe/Istanbul')).strftime(time_format)
bang_color = day_colors['day'] if isDaytime1(bang_time,twelvehours) else day_colors['night']
istan_color = day_colors['day'] if isDaytime1(istan_time,twelvehours) else day_colors['night']
if not display_p:
istan_time = istan_time.replace("PM", "").replace("AM", "")
bang_time = bang_time.replace("PM", "").replace("AM", "")
draw.text((world_offset, 1), bang_time, bang_color, font_1)
draw.text((world_offset, 9), istan_time, istan_color, font_1)
draw.line([0,7,128,7],(50,50,50), width=1)
draw.text((3, 1), 'BANGKOK', time_colors1[worldcity_color], font_1)
draw.text((3, 9), 'ISTANBUL', time_colors1[worldcity_color], font_1)
if the_time >= next_six_seconds:
counter += 1
next_six_seconds = the_time + 6
if counter > 6:
counter = 1
if time.time() - update_t1 > delay_t1:
update_t1 = time.time()
#Get the pause time right before image is done transitioning in
if offset_y1 == -1 or offset_x1 == 1:
pause_time = time.time() + pause1
if offset_y1 < 0:
offset_y1+=1
else: #If the scrolling reaches 0 pixel, pause it
if offset_x1 != 0:
offset_x1 -= 1
else:
try: #after the pause time, scroll iamge past 0 pixel to continue scrolling
if time.time() >= pause_time:
offset_x1 -= 1
except:
pass
#NORMAL SCROLLING
elif 'Clock' not in top[i1 % len(top)]:
if time.time() - update_t1 > delay_t1:
update_t1 = time.time()
if offset_y1 < 0:
offset_y1+=1
else:
offset_x1 -= 1
#BOTTOM ROW
if 'Clock' not in bottom[i2 % len(bottom)]:
if time.time() - update_t2 > delay_t2:
update_t2 = time.time()
if offset_y2 > 16:
offset_y2-=1
else:
offset_x2 -= 1
# SCROLL, DISPLAY, PAUSE CLOCK 2
elif bottom[i2 % len(bottom)] == 'Clock 2':
#Initial image generation so it doesn't appear blank for the first second
if offset_x2 == 128 or offset_y2 == 32:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
current_time_b = datetime.now(pytz.timezone(timezone1_b)).strftime(time_format_b + ",%a %d %b %Y").split(',')
time_t_b = current_time_b[0]
date_t_b = current_time_b[1].upper()
date_width_b, date_height_b = draw2.textsize(date_t_b, font2_b)
text_width_b, text_height_b = draw2.textsize(time_t_b, font_b)
draw2.text(((128-text_width_b)/2, -2), time_t_b, time_colors1[time_color1_b], font_b)
draw2.text(((128-date_width_b)/2, 8), date_t_b, time_colors1[date_color1_b], font2_b)
#If time now is greater than 1 second of the previously updated image time, update image and reset updated image time to another second
if time.time() >= the_time2 + 1:
the_time2 = time.time()
draw2.rectangle([(0,0),(128,16)], (0,0,0))
current_time_b = datetime.now(pytz.timezone(timezone1_b)).strftime(time_format_b + ",%a %d %b %Y").split(',')
time_t_b = current_time_b[0]
date_t_b = current_time_b[1].upper()
date_width_b, date_height_b = draw2.textsize(date_t_b, font2_b)
text_width_b, text_height_b = draw2.textsize(time_t_b, font_b)
draw2.text(((128-text_width_b)/2, -2), time_t_b, time_colors1[time_color1_b], font_b)
draw2.text(((128-date_width_b)/2, 8), date_t_b, time_colors1[date_color1_b], font2_b)
if time.time() - update_t2 > delay_t2:
update_t2 = time.time()
#Get the pause time right before image is done transitioning in
if offset_y2 == 17 or offset_x2 == 1:
pause_time2 = time.time() + pause2
if offset_y2 > 16:
offset_y2-=1
else: #If the scrolling reaches 0 pixel, pause it
if offset_x2 != 0:
offset_x2 -= 1
else:
try: #after the pause time, scroll iamge past 0 pixel to continue scrolling
if time.time() >= pause_time2:
offset_x2 -= 1
except:
pass
# SCROLL, DISPLAY, PAUSE CLOCK 1
elif bottom[i2 % len(bottom)] == 'Clock 1':
#Initial image generation so it doesn't appear blank for the first second
if offset_x2 == 128 or offset_y2 == 32:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
current_time_b = datetime.now(pytz.timezone(timezone2_b)).strftime(time_format_b + ",%A,%d %b").split(',')
time_t_b = current_time_b[0]
weekday_t_b = current_time_b[1].upper()
date_t_b = current_time_b[2].upper()
date_width_b, date_height_b = draw2.textsize(date_t_b, font_2_b)
wday_width_b, wday_height_b = draw2.textsize(weekday_t_b, font_2_b)
text_width_b, text_height_b = draw2.textsize(time_t_b, font_1_b)
total_width_b = text_width_b + 5 + max(wday_width_b, date_width_b)
starting_coord_b = (128-total_width_b)/2
draw2.text((starting_coord_b, 1), time_t_b, time_colors1[time_color2_b], font_1_b)
draw2.text((starting_coord_b + text_width_b + 5, 1), date_t_b, time_colors1[date_color2_b], font_2_b)
draw2.text((starting_coord_b + text_width_b + 6, 8), weekday_t_b, time_colors1[weekday_color2_b], font_2_b)
#If time now is greater than 1 second of the previously updated image time, update image and reset updated image time to another second
if time.time() >= the_time2 + 1:
the_time2 = time.time()
draw2.rectangle([(0,0),(128,16)], (0,0,0))
current_time_b = datetime.now(pytz.timezone(timezone2_b)).strftime(time_format_b + ",%A,%d %b").split(',')
time_t_b = current_time_b[0]
weekday_t_b = current_time_b[1].upper()
date_t_b = current_time_b[2].upper()
date_width_b, date_height_b = draw2.textsize(date_t_b, font_2_b)
wday_width_b, wday_height_b = draw2.textsize(weekday_t_b, font_2_b)
text_width_b, text_height_b = draw2.textsize(time_t_b, font_1_b)
total_width_b = text_width_b + 5 + max(wday_width_b, date_width_b)
starting_coord_b = (128-total_width_b)/2
draw2.text((starting_coord_b, 1), time_t_b, time_colors1[time_color2_b], font_1_b)
draw2.text((starting_coord_b + text_width_b + 5, 1), date_t_b, time_colors1[date_color2_b], font_2_b)
draw2.text((starting_coord_b + text_width_b + 6, 8), weekday_t_b, time_colors1[weekday_color2_b], font_2_b)
if time.time() - update_t2 > delay_t2:
update_t2 = time.time()
#Get the pause time right before image is done transitioning in
if offset_y2 == 17 or offset_x2 == 1:
pause_time2 = time.time() + pause2
if offset_y2 > 16:
offset_y2-=1
else: #If the scrolling reaches 0 pixel, pause it
if offset_x2 != 0:
offset_x2 -= 1
else:
try: #after the pause time, scroll iamge past 0 pixel to continue scrolling
if time.time() >= pause_time2:
offset_x2 -= 1
except:
pass
# SCROLL, DISPLAY, PAUSE WORLD CLOCK
elif bottom[i2 % len(bottom)] == 'World Clock':
#Initial image generation so it doesn't appear blank for the first second
if offset_x2 == 128 or offset_y2 == 32:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
ny_time_b = datetime.now(pytz.timezone('America/New_York')).strftime(time_format_b)
london_time_b = datetime.now(pytz.timezone('Europe/London')).strftime(time_format_b)
ny_color_b = day_colors['day'] if isDaytime1(ny_time_b,twelvehours_b) else day_colors['night']
london_color_b = day_colors['day'] if isDaytime1(london_time_b,twelvehours_b) else day_colors['night']
if not display_p_b:
ny_time_b = ny_time_b.replace("PM", "").replace("AM", "")
london_time_b = london_time_b.replace("PM", "").replace("AM", "")
draw2.text((world_offset_b, 1), ny_time_b, ny_color_b, font_12)
draw2.text((world_offset_b, 9), london_time_b, london_color_b, font_12)
draw2.line([0,7,128,7],(50,50,50), width=1)
draw2.text((3, 1), 'NEW YORK', time_colors1[worldcity_color2], font_12)
draw2.text((3, 9), 'LONDON', time_colors1[worldcity_color2], font_12)
#If time now is greater than 1 second of the previously updated image time, update image and reset updated image time to another second
if time.time() >= the_time2 + 1:
the_time2 = time.time()
if counter2 == 0 or counter2 == 1:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
ny_time_b = datetime.now(pytz.timezone('America/New_York')).strftime(time_format_b)
london_time_b = datetime.now(pytz.timezone('Europe/London')).strftime(time_format_b)
ny_color_b = day_colors['day'] if isDaytime1(ny_time_b,twelvehours_b) else day_colors['night']
london_color_b = day_colors['day'] if isDaytime1(london_time_b,twelvehours_b) else day_colors['night']
if not display_p_b:
ny_time_b = ny_time_b.replace("PM", "").replace("AM", "")
london_time_b = london_time_b.replace("PM", "").replace("AM", "")
draw2.text((world_offset_b, 1), ny_time_b, ny_color_b, font_12)
draw2.text((world_offset_b, 9), london_time_b, london_color_b, font_12)
draw2.line([0,7,128,7],(50,50,50), width=1)
draw2.text((3, 1), 'NEW YORK', time_colors1[worldcity_color2], font_12)
draw2.text((3, 9), 'LONDON', time_colors1[worldcity_color2], font_12)
elif counter2 == 2:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
tokyo_time_b = datetime.now(pytz.timezone('Asia/Tokyo')).strftime(time_format_b)
au_time_b = datetime.now(pytz.timezone('Australia/Sydney')).strftime(time_format_b)
tokyo_color_b = day_colors['day'] if isDaytime1(tokyo_time_b,twelvehours_b) else day_colors['night']
au_color_b = day_colors['day'] if isDaytime1(au_time_b,twelvehours_b) else day_colors['night']
if not display_p_b:
au_time_b = au_time_b.replace("PM", "").replace("AM", "")
tokyo_time_b = tokyo_time_b.replace("PM", "").replace("AM", "")
draw2.text((world_offset_b, 1), tokyo_time_b, tokyo_color_b, font_12)
draw2.text((world_offset_b, 9), au_time_b, au_color_b, font_12)
draw2.line([0,7,128,7],(50,50,50), width=1)
draw2.text((3, 1), 'TOKYO', time_colors1[worldcity_color2], font_12)
draw2.text((3, 9), 'SYDNEY', time_colors1[worldcity_color2], font_12)
elif counter2 == 3:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
dubai_time_b = datetime.now(pytz.timezone('Asia/Dubai')).strftime(time_format_b)
la_time_b = datetime.now(pytz.timezone('America/Los_Angeles')).strftime(time_format_b)
dubai_color_b = day_colors['day'] if isDaytime1(dubai_time_b,twelvehours_b) else day_colors['night']
la_color_b = day_colors['day'] if isDaytime1(la_time_b,twelvehours_b) else day_colors['night']
if not display_p_b:
dubai_time_b = dubai_time_b.replace("PM", "").replace("AM", "")
la_time_b = la_time_b.replace("PM", "").replace("AM", "")
draw2.text((world_offset_b, 1), dubai_time_b, dubai_color_b, font_12)
draw2.text((world_offset_b, 9), la_time_b, la_color_b, font_12)
draw2.line([0,7,128,7],(50,50,50), width=1)
draw2.text((3, 1), 'DUBAI', time_colors1[worldcity_color2], font_12)
draw2.text((3, 9), 'LOS ANGELES', time_colors1[worldcity_color2], font_12)
elif counter2 == 4:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
cn_time_b = datetime.now(pytz.timezone('Asia/Shanghai')).strftime(time_format_b)
paris_time_b = datetime.now(pytz.timezone('Europe/Paris')).strftime(time_format_b)
cn_color_b = day_colors['day'] if isDaytime1(cn_time_b,twelvehours_b) else day_colors['night']
paris_color_b = day_colors['day'] if isDaytime1(paris_time_b,twelvehours_b) else day_colors['night']
if not display_p_b:
cn_time_b = cn_time_b.replace("PM", "").replace("AM", "")
paris_time_b = paris_time_b.replace("PM", "").replace("AM", "")
draw2.text((world_offset_b, 1), cn_time_b, cn_color_b, font_12)
draw2.text((world_offset_b, 9), paris_time_b, paris_color_b, font_12)
draw2.line([0,7,128,7],(50,50,50), width=1)
draw2.text((3, 1), 'SHANGHAI', time_colors1[worldcity_color2], font_12)
draw2.text((3, 9), 'PARIS', time_colors1[worldcity_color2], font_12)
elif counter2 == 5:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
in_time_b = datetime.now(pytz.timezone('Asia/Kolkata')).strftime(time_format_b)
auck_time_b = datetime.now(pytz.timezone('Pacific/Auckland')).strftime(time_format_b)
in_color_b = day_colors['day'] if isDaytime1(in_time_b,twelvehours_b) else day_colors['night']
auck_color_b = day_colors['day'] if isDaytime1(auck_time_b,twelvehours_b) else day_colors['night']
if not display_p_b:
in_time_b = in_time_b.replace("PM", "").replace("AM", "")
auck_time_b = auck_time_b.replace("PM", "").replace("AM", "")
draw2.text((world_offset_b, 1), in_time_b, in_color_b, font_12)
draw2.text((world_offset_b, 9), auck_time_b, auck_color_b, font_12)
draw2.line([0,7,128,7],(50,50,50), width=1)
draw2.text((3, 1), 'MUMBAI', time_colors1[worldcity_color2], font_12)
draw2.text((3, 9), 'AUCKLAND', time_colors1[worldcity_color2], font_12)
elif counter2 == 6:
draw2.rectangle([(0,0),(128,16)], (0,0,0))
bang_time_b = datetime.now(pytz.timezone('Asia/Bangkok')).strftime(time_format_b)
istan_time_b = datetime.now(pytz.timezone('Europe/Istanbul')).strftime(time_format_b)
bang_color_b = day_colors['day'] if isDaytime1(bang_time_b,twelvehours_b) else day_colors['night']
istan_color_b = day_colors['day'] if isDaytime1(istan_time_b,twelvehours_b) else day_colors['night']
if not display_p_b:
istan_time_b = istan_time_b.replace("PM", "").replace("AM", "")
bang_time_b = bang_time_b.replace("PM", "").replace("AM", "")
draw2.text((world_offset_b, 1), bang_time_b, bang_color_b, font_12)
draw2.text((world_offset_b, 9), istan_time_b, istan_color_b, font_12)
draw2.line([0,7,128,7],(50,50,50), width=1)
draw2.text((3, 1), 'BANGKOK', time_colors1[worldcity_color2], font_12)
draw2.text((3, 9), 'ISTANBUL', time_colors1[worldcity_color2], font_12)
if the_time2 >= next_six_seconds2:
counter2 += 1
next_six_seconds2 = the_time2 + 6
if counter2 > 6:
counter2 = 1
if time.time() - update_t2 > delay_t2:
update_t2 = time.time()
#Get the pause time right before image is done transitioning in
if offset_y2 == 17 or offset_x2 == 1:
pause_time2 = time.time() + pause2
if offset_y2 > 16:
offset_y2-=1
else: #If the scrolling reaches 0 pixel, pause it
if offset_x2 != 0:
offset_x2 -= 1
else:
try: #after the pause time, scroll iamge past 0 pixel to continue scrolling
if time.time() >= pause_time2:
offset_x2 -= 1
except:
pass
if kill: break
# SCROLLING OF THE IMAGE
self.double_buffer.SetImage(image1, offset_x1, offset_y1)
self.double_buffer.SetImage(image2, offset_x2, offset_y2)
# remove the ppixels behind the image, to stop trailing
self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer)
for y in range(16):
self.matrix.SetPixel(offset_x1 + img_width1 +1 , y , 0,0,0)
self.matrix.SetPixel(offset_x1 + img_width1 , y , 0,0,0)
for y in range(16,32):
self.matrix.SetPixel(offset_x2 + img_width2 +1 , y , 0,0,0)
self.matrix.SetPixel(offset_x2 + img_width2 , y , 0,0,0)
kill = self.checkKilled()
if kill: break
def scrollMultiple(self, animation = 'down'):
# scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed
# read lines from csv
images = []
delays = []
kinds = []
f = open('csv/multiple.csv', 'r')
CSV = csv.reader(f)
next(CSV)
font = ImageFont.load("./fonts/texgyre-27.pil")
for row in CSV:
kind, content, delay = row
delays.append(delay)
kinds.append(kind)
if kind == 'text':
images.append(self.textImage(content, font, 255, 255, 0, True, w_buff = 50))
elif kind == 'image':
images.append(self.openImage(content).convert('RGB'))
elif kind == 'gif':
images.append(self.openImage(content))
f.close()
kill = False
i = 0 # keep track of which image we are displaying
self.double_buffer = self.matrix.CreateFrameCanvas()
while True:
image = images[i%len(images)]
delay = delays[i%len(images)]
kind = kinds[i%len(images)]
img_width, img_height = image.size
offset_x = 0
if animation == 'traditional':
offset_x = 128
elif animation == 'continuous':
offset_x = 0
elif animation in ['up', 'down']:
offset_x = max(0, 128-img_width)
offset_y = 0
#first scroll image in from bottom
frame_skip = int((1/15)/self.delay) #controls how fast gifs run
self.frame = 0
pause_frames = int(float(delay)/self.delay)
if animation == 'up':
offset_y = 33
direction = -1
kill = self.scrollImageY(image, direction = direction, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = kind=='gif')
elif animation == 'down':
direction = 1
offset_y = -33
kill = self.scrollImageY(image, direction = direction, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = kind=='gif')
offset_y = 0
if kill: break
kill = self.scrollImage(image, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = kind=='gif', pause_frames = pause_frames)
if kill: break
i+=1
def textImage(self, text, font, r = 255, g = 255, b = 255, matrix_height = False, w_buff = 3, h_buff = 3, background = False, location = False):
#creates and returns a ppm image containing the text in the supplied font and colour
width, height = self.get_text_dimensions(text, font)
if matrix_height:
height = 32
img = Image.new('RGB', (width + w_buff, height + h_buff))
d = ImageDraw.Draw(img)