0

Trying to split timestamp values in a dictionary using ".strptime"

So I have a set of values which have been imported into a dictionary from a .CSV file. These are in the format hh:mm:ss but not the correct datatype to use the '.strptime' function. The end result is to convert each timestamp in the dictionary into seconds however I can't seem to get the '.strptime' to work since the values are the wrong datatype. is the ".strptime" function even the right one to use?

The code so far:

from datetime import time
InTime=open("CameraIn.csv", 'rt')
OutTime=open("CameraOut.csv",'rt')

SpeedLimit = int(input("what is the speed limit? "))
#SpeedLimit = SpeedLimit*2.23694

line = InTime.readline()

InTimeByReg={}
OutTimeByReg={}

#def Speeding_Test(key):
#MetresInSeconds = int(OutTimeByReg(key)) - int(InTimeByReg(key))
#if MetresInSeconds > 26:
#    SpeedingCars = open("SpeedingCars.txt", "a")
#    SpeedingCars.write(str(key))


for line in InTime:
  (reg,time)= line.split(",")
  InTimeByReg[reg]=time.strip()

for line in OutTime:
  (reg,time)= line.split(",")
  OutTimeByReg[reg]=time.strip()

#for key in InTimeByReg:
#  Speeding_Test(key)

The files I have imported are as follows:

(CamerIn.csv): BD51 SMR,00:01:24 AV51 CDR,02:24:02 FP05 KLR,05:48:17 AH09 DPU,10:12:56 KL03 ZRC,16:43:59

(CameraOut.csv): BD51 SMR,00:02:00 AV51 CDR,02:24:42 FP05 KLR,05:48:58 AH09 DPU,10:13:20 KL03 ZRC,16:44:14

So far, here is the output from the code:

0 Answers0