Browse Source

Sometimes the decrypted files have fluff at the end which could confuse the python script. Added condition to check

Rafael Arce Nazario 6 years ago
parent
commit
4d92f078a0
1 changed files with 20 additions and 16 deletions
  1. 20
    16
      tp-smart-process.py

+ 20
- 16
tp-smart-process.py View File

30
     # for each line in the text file, extract the tokens, compute the time diff
30
     # for each line in the text file, extract the tokens, compute the time diff
31
     # and accumulate in dictionary
31
     # and accumulate in dictionary
32
 
32
 
33
+    maxTokenIdx = max(tokenApp, tokenMonth, tokenDay, tokenYear, tokenTime)
34
+
33
     isFirst = True
35
     isFirst = True
34
     for event in fileContent:
36
     for event in fileContent:
35
 #         print("evenToken:", tokenTime)
37
 #         print("evenToken:", tokenTime)
36
 #         print (event[tokenTime])
38
 #         print (event[tokenTime])
37
-        (hour, minutes, seconds) = event[tokenTime].split(':') 
38
-        
39
-        (year, month, day) = (int(event[tokenYear]), monthDict[event[tokenMonth]],int(event[tokenDay]))
40
-        currDateTime = datetime.datetime(year, month, day, int(hour), int(minutes), int(seconds)) 
41
-#         print(event, currDateTime, event[tokenApp])
42
-        if (not isFirst):
43
-            timeDelta = currDateTime - prevDateTime 
44
-#             print(timeDelta, prevApp)
45
-            if prevApp in appDict:
46
-                appDict[prevApp] = appDict[prevApp] + timeDelta.seconds 
39
+
40
+        if len(event) > maxTokenIdx:
41
+            (hour, minutes, seconds) = event[tokenTime].split(':') 
42
+            
43
+            (year, month, day) = (int(event[tokenYear]), monthDict[event[tokenMonth]],int(event[tokenDay]))
44
+            currDateTime = datetime.datetime(year, month, day, int(hour), int(minutes), int(seconds)) 
45
+    #         print(event, currDateTime, event[tokenApp])
46
+            if (not isFirst):
47
+                timeDelta = currDateTime - prevDateTime 
48
+    #             print(timeDelta, prevApp)
49
+                if prevApp in appDict:
50
+                    appDict[prevApp] = appDict[prevApp] + timeDelta.seconds 
51
+                else:
52
+                    appDict[prevApp] = 0 + timeDelta.seconds
47
             else:
53
             else:
48
-                appDict[prevApp] = 0 + timeDelta.seconds
49
-        else:
50
-            isFirst = False
51
-        prevDateTime = currDateTime
52
-        prevApp = event[tokenApp]
54
+                isFirst = False
55
+            prevDateTime = currDateTime
56
+            prevApp = event[tokenApp]
53
 
57
 
54
     return appDict
58
     return appDict
55
 
59
 
68
     # print("Is this a time? ", fileContent[0][tokenTime])
72
     # print("Is this a time? ", fileContent[0][tokenTime])
69
     # print("Is this a year month day? ", fileContent[0][tokenYear], fileContent[0][tokenMonth], fileContent[0][tokenDay])
73
     # print("Is this a year month day? ", fileContent[0][tokenYear], fileContent[0][tokenMonth], fileContent[0][tokenDay])
70
     # print("If not, modify the token values....")
74
     # print("If not, modify the token values....")
71
-#     print(fileContent)
75
+    # print(fileContent)
72
 #     print([line for line in fileContent if len(line) > 10])
76
 #     print([line for line in fileContent if len(line) > 10])
73
     return processAppTimes([line for line in fileContent if len(line) > 10])
77
     return processAppTimes([line for line in fileContent if len(line) > 10])
74
 
78