-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathidleTime.py
58 lines (51 loc) · 1.8 KB
/
idleTime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import datetime
import sys
import json
import os
import uploader
if sys.platform == 'win32':
from ctypes import *
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_int),
]
def get_idle_duration():
lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
if windll.user32.GetLastInputInfo(byref(lastInputInfo)):
millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
return millis / 1000.0
else:
return 0
else:
def get_idle_duration():
return 0
def IdleCalculator():
import time
TotalIdleTime = 0
TodayDate = datetime.datetime.now()
while 1:
TodayDate = datetime.datetime.now()
if(TodayDate.hour==23):
break
duration = get_idle_duration()
TotalIdleTime += duration
#print('User idle for {0:0.2f} seconds.'.format(duration))
sys.stdout.flush()
time.sleep(5)
#print('Total idle time: {0:0.2f} seconds.'.format(TotalIdleTime))
Data = {
"Date" : TodayDate.strftime('%Y%m%d'),
"Total_Idle_Time": TotalIdleTime
}
CurrentFolder = os.getcwd()
DateInString = TodayDate.strftime('%Y%m%d')
fp = CurrentFolder +"\\" + DateInString
filename = "TotalIdleTime" + DateInString + ".json"
fullPath = fp + "\\"+ filename
with open("{}\\{}\\TotalIdleTime{}.json".format(os.getcwd(),TodayDate.strftime('%Y%m%d'),TodayDate.strftime('%Y%m%d')),"w+")as myFile:
json.dump(Data, myFile)
FolderID = uploader.createFolder(DateInString + " json")
uploader.UploadFile(filename,fullPath,"text/json",FolderID)
#print("File:"+filename)