Code examples for Bible
# Test font size to determine the maximum number of characters per line and should match the default font used in draw_text | |
test_font = inkyphat.ImageFont.truetype(inkyphat.fonts.AmaticSC,20) | |
w, h = test_font.getsize("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
max_char = int((212/(w/36))) |
quotes = open("quotes", "r") | |
lines = quotes.readlines() | |
quotes.close() | |
maximum = len(lines) | |
choice=(randint(1,maximum-1)) | |
test = str(lines[choice]) | |
text = [test[i:i+max_char] for i in range(0,len(test),max_char)] |
for i in range(len(text)): | |
new_text=text[i] | |
if (new_text[max_char-1:max_char])!=" ": | |
new_text=new_text+"-" | |
if (new_text[-2:-1:])==".": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==",": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==";": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==":": | |
new_text=new_text[:-1] | |
if (new_text[-2:-1:])==" ": | |
new_text=new_text[:-1] | |
text[i]=new_text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment