PushingScores/00-draft-push-it-to-the-limit.py

81 lines
2.0 KiB
Python
Raw Normal View History

2019-05-12 06:11:51 +02:00
from PIL import Image, ImageDraw, ImageFont
import pytextcanvas as pytc
import numpy as np
import json
import datetime
wordpath = []
idlist = []
timelist = []
timelistforoperations = []
with open('usersessiondata.json', encoding='utf-8') as data_file:
data = json.loads(data_file.read())
wordpath = data["wordpath"]
idlist = data["id"]
timelist = data["clicktime"]
# timelist = [i.replace('"', '') for i in timelist]
print(wordpath[1])
print(idlist[1])
print(timelist[1])
for t in timelist :
yo = datetime.datetime.strptime(t, '%Y-%m-%d_%H:%M:%S')
timelistforoperations.append(yo)
# difftime = timelistforoperations[2] - timelistforoperations[1]
# diffseconds= difftime.seconds
# print("diff in seconds: ")
# print(diffseconds)
prev = None
for (word, time, uniqueid) in zip(wordpath,timelistforoperations, idlist):
filler = int(uniqueid)
upperword = word.upper()
#get previous time for substraction
if not (prev is None):
difftime = time - prev
difftime = difftime.total_seconds()
difftime = int(difftime)
# print(difftime)
else:
difftime = 1
test = difftime + 4
# canvas = pytc.Canvas(60, test)
# canvas.fill(".")
# canvas.cursor = (filler, difftime)
# canvas.write(upperword)
# # l2 = [ord(c) for c in wordpath[1]]
# # canvas.write(l2)
# canvas.rectangle(".", -1, -1, 60, test)
prev = time
# print(canvas)
# myfont = ImageFont.truetype("fonts/NotCourierSans-Bold.ttf", 12)
# for (word, time, uniqueid) in zip(wordpath,timelist, idlist):
# size = myfont.getsize(str(word))
# img = Image.new("1",size,"black")
# draw = ImageDraw.Draw(img)
# draw.text((0, 0), str(word), "white", font=myfont)
# pixels = np.array(img, dtype=np.uint8)
# numfilling = uniqueid
# chars = np.array([' ',numfilling], dtype="U1")[pixels]
# strings = chars.view('U' + str(chars.shape[1])).flatten()
# score = "\n".join(strings)
# print(score)
# with open("index.txt", "a") as myfile:
# myfile.write(score)