2019-09-12 19:53:57 +02:00
|
|
|
#!/usr/bin/env python3
|
2019-09-09 17:32:07 +02:00
|
|
|
from PIL import Image
|
|
|
|
from PIL import ImageFont
|
|
|
|
from PIL import ImageDraw
|
|
|
|
import csv
|
|
|
|
import random
|
|
|
|
|
2019-09-12 19:53:57 +02:00
|
|
|
def fetchText(indText):
|
|
|
|
with open("rtext.csv") as rtext:
|
2019-09-13 02:01:21 +02:00
|
|
|
csvReader = csv.reader(rtext,delimiter=';')
|
2019-09-12 19:53:57 +02:00
|
|
|
for row in csvReader:
|
2019-09-17 00:20:30 +02:00
|
|
|
if len(row)>1:
|
|
|
|
if row[0]==indText:
|
|
|
|
return row[1],row[2],row[random.randint(3,len(row)-1)].replace('@','\n')
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
2019-09-13 02:01:21 +02:00
|
|
|
def fetch2Text(indText):
|
|
|
|
with open("r2text.csv") as rtext:
|
|
|
|
csvReader = csv.reader(rtext,delimiter=';')
|
|
|
|
for row in csvReader:
|
2019-09-17 00:20:30 +02:00
|
|
|
if len(row)>1:
|
|
|
|
if row[0]==indText:
|
|
|
|
rand1 = random.randint(5,len(row)-1)
|
|
|
|
if rand1 %2 == 0:
|
|
|
|
rand1 +=1
|
|
|
|
rand2 = rand1+1
|
|
|
|
return row[1],row[2],row[3],row[4],row[rand1].replace('@','\n'),row[rand2].replace('@','\n')
|
|
|
|
else:
|
|
|
|
return 0
|
2019-09-13 02:01:21 +02:00
|
|
|
|
2019-09-09 17:32:07 +02:00
|
|
|
def fetchVign():
|
|
|
|
starts = []
|
|
|
|
startdest = []
|
|
|
|
nvign = 0
|
|
|
|
currVign = "000"
|
|
|
|
story = []
|
|
|
|
with open("ram.csv") as ram:
|
|
|
|
csvReader = csv.reader(ram)
|
|
|
|
for row in csvReader:
|
|
|
|
starts.append(row[0])
|
|
|
|
startdest.append(row)
|
|
|
|
while nvign <= 3:
|
|
|
|
story.append(startdest[starts.index(currVign)][random.randint(1,len(startdest[starts.index(currVign)])-1)])
|
|
|
|
currVign = story[nvign]
|
|
|
|
if story[nvign] == "B00":
|
|
|
|
story[nvign] += "."
|
|
|
|
story[nvign] += str(random.randint(0,2))
|
2019-09-17 00:20:30 +02:00
|
|
|
story[nvign]+=".png"
|
2019-09-09 17:32:07 +02:00
|
|
|
nvign +=1
|
|
|
|
return story
|
|
|
|
|
2019-09-13 16:08:09 +02:00
|
|
|
def addThing(vign):
|
|
|
|
#TODO
|
|
|
|
pass
|
|
|
|
|
2019-09-12 19:53:57 +02:00
|
|
|
def writeStrip(story):
|
2019-09-17 00:20:30 +02:00
|
|
|
strip = []
|
2019-09-12 19:53:57 +02:00
|
|
|
for indVign in story:
|
|
|
|
if indVign!="000":
|
|
|
|
vign = Image.open(indVign)
|
|
|
|
addtext = ImageDraw.Draw(vign)
|
|
|
|
fnt = ImageFont.truetype("ubuntu.ttf",16)
|
2019-09-13 02:01:21 +02:00
|
|
|
if indVign[0] == 'A':
|
|
|
|
textVign = fetchText(indVign)
|
2019-09-17 00:20:30 +02:00
|
|
|
if textVign !=0:
|
|
|
|
addtext.multiline_text((int(textVign[0]),int(textVign[1])),textVign[2],fill="#000000",font=fnt,align="center")
|
2019-09-13 02:01:21 +02:00
|
|
|
else:
|
|
|
|
textVign = fetch2Text(indVign)
|
2019-09-17 00:20:30 +02:00
|
|
|
if textVign!=0:
|
|
|
|
addtext.multiline_text((int(textVign[0]),int(textVign[1])),textVign[4],fill="#000000",font=fnt,align="center")
|
|
|
|
addtext.multiline_text((int(textVign[2]),int(textVign[3])),textVign[5],fill="#000000",font=fnt,align="center")
|
2019-09-13 16:08:09 +02:00
|
|
|
obj = addThing(indVign)
|
|
|
|
if obj!=(0,0):
|
|
|
|
#TODO
|
|
|
|
pass
|
2019-09-17 00:20:30 +02:00
|
|
|
strip.append(vign)
|
|
|
|
image = Image.new('RGB',(2400,500))
|
|
|
|
xshift=0
|
|
|
|
for vign in strip:
|
|
|
|
image.paste(vign,(xshift,0))
|
|
|
|
xshift += 600
|
|
|
|
return image
|
2019-09-09 17:32:07 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-09-17 00:20:30 +02:00
|
|
|
story = fetchVign()
|
|
|
|
finalStrip = writeStrip(story)
|
|
|
|
finalStrip.show()
|