In this below code execution you will be able to record every step on window.
Language: Python
Lib: Win32 , OS, Tikinter, datetime, time & Openpyxl
import win32gui
import time
import datetime
import openpyxl
import os
import tkinter as tk
from tkinter import *
w=win32gui
from openpyxl import Workbook
print("\t Copyright Reserved: @Rohit Kankhedia #.com \n\n \t\t india \n\t This window will autoclose after 30 sec session \n\t your resule will be exported in C:/te/")
home_dir = ('C:\Te')
if not os.path.isdir(home_dir):
os.makedirs(home_dir)
#print("Home directory %s was created." %home_dir)
book = Workbook()
sheet = book.active
value_1=[]
value_2=[]
val=str(w.GetWindowText (w.GetForegroundWindow()))
sheet["B1"].value="Task"
sheet["C1"].value="Time"
sheet["D1"].value="DateTime_IF_Change"
sheet["E1"].value="Time_IF_Change"
sheet["F1"].value="Time_Spent on Task"
def Start1():
#counter_label(label)
for i in range(2, 30):
time.sleep(1)
#if str(w.GetWindowText (w.GetForegroundWindow()))!=NewTask[i]:
# NewTask[i]=str(w.GetWindowText (w.GetForegroundWindow()))
# NewTime[i]=datetime.datetime.now()
value_1.append(str(w.GetWindowText (w.GetForegroundWindow())))
value_2.append(datetime.datetime.now())
#OldTime[i]=datetime.datetime.now()
#print(str(w.GetWindowText (w.GetForegroundWindow())),datetime.datetime.now())
for i in range(2,28):
print(value_1[i],value_2[i])
if i==2 or i==27:
sheet["D"+str(i)].value=value_2[i]
sheet["E"+str(i)].value='=HOUR(D{0})&":"&MINUTE(D{0})&":"&SECOND(D{0})'.format(i)
if i!=2 :
sheet["F"+str(i)].value=value_2[i]-temp1
temp1=value_2[i]
if value_1[i]!=value_1[i-1]:
#temp=value_1[i]
sheet["D"+str(i)].value=value_2[i]
sheet["E"+str(i)].value='=HOUR(D{0})&":"&MINUTE(D{0})&":"&SECOND(D{0})'.format(i)
sheet["F"+str(i)].value=value_2[i]-temp1
temp1=value_2[i]
sheet["B"+str(i)].value=value_1[i]
sheet["C"+str(i)].value=str(value_2[i])
book.save("c:\\Te\\Track_R.xlsx")
root.destroy()
root = tk.Tk()
root.title('Time-12-Track')
time1 = ''
clock = Label(root, font=('times', 20, 'bold'), bg='green')
clock.pack(fill=BOTH, expand=1)
def tick():
global time1
# get the current local time from the PC
time2 = time.strftime('%H:%M:%S')
# if time string has changed, update it
if time2 != time1:
time1 = time2
clock.config(text=time2)
# calls itself every 200 milliseconds
# to update the time display as needed
# could use >200 ms, but display gets jerky
clock.after(200, tick)
tick()
tk.Label(root,
text="\t Copyright Reserved: @Rohit Kankhedia #BT.com \n\n\t BT india \n\t This window will autoclose after 30 sec session \n\t your resule will be exported in C:/te/",
fg = "red",
font = "Times").pack()
button = tk.Button(root, text='Start', width=25, command=Start1)
button.pack()
counter = 0
button1 = tk.Button(root, text='Stop', width=25, command=root.destroy)
button1.pack()
root.mainloop()
Tool Screen:
No comments:
Post a Comment