Reputation: 15
Here is the specific line I am using line.find for:
Alta,"08-10-2019 16:34:42","08-10-2019 18:03:42","RESOLVIDO","roteador-assu-tely","Host indisponÃvel","1h 29m","Não","",""
Obviously, there are many other lines since its a full CSV file, but lets focus on this specific line right now. I am using a split(',') to separate the lines and trying to generate a datetime object with it, what am I doing wrong?
with open(path + "zbx_problems_export.csv", "r") as f:
lines = f.readlines()
inicio_expediente = datetime.time(6, 40, 00)
fim_expediente = datetime.time(16, 30, 00)
for line in lines:
if line.find('roteador-assu-tely') >= 0:
a = line.split(',')
data_inicio = datetime.datetime.strptime(a[1], '"%d-%m-%Y %H:%M:%S"')
data_fim = datetime.datetime.strptime(a[2], '"%d-%m-%Y %H:%M:%S"')
if data_inicio.time > inicio_expediente.time and data_inicio.time < fim_expediente.time and data_inicio.weekday() != 5 and data_inicio.weekday() != 6:
the full error message is:
Traceback (most recent call last):
File "ScriptPythonRelatorioProto.py", line 31, in <module>
if data_inicio.time > inicio_expediente.time and data_inicio.time < fim_expediente.time and data_inicio.weekday() != 5 and data_inicio.weekday() != 6:
AttributeError: 'datetime.time' object has no attribute 'time'
Line 31 is the last time in the sample code posted
Upvotes: 0
Views: 55
Reputation: 522625
inicio_expediente = datetime.time(6, 40, 00)
[..]
inicio_expediente.time
inicio_expediente
is a time
object, it doesn't have a .time
attribute. Just remove the .time
here.
You then have another issue here: data_inicio.time
.
data_inicio
is a datetime
object and it has a .time
, but that's a method, not a plain attribute, so that must be data_inicio.time()
.
Upvotes: 1