Skip to content

Commit

Permalink
- fixed age timer
Browse files Browse the repository at this point in the history
  • Loading branch information
cklewar committed Apr 9, 2018
1 parent fd6d46a commit f7ccae8
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,22 @@ def getActiveFlowRoutes(self):

hash_object = hashlib.sha512(b'{0}{1}'.format(str(destination), str(value['ip'])))
hex_dig = hash_object.hexdigest()

_age = dict()
pattern = r'(.*)\s(.*?):(.*?):(.*)'
regex = re.compile(pattern)
age = re.findall(regex, flow.age)

if len(age[0]) == 1:
_age['current'] = datetime.timedelta(seconds=int(age[0][3]))
elif len(age[0]) == 2:
_age['current'] = datetime.timedelta(minutes=int(age[0][2]), seconds=int(age[0][3]))
elif len(age[0]) == 3:
_age['current'] = datetime.timedelta(hours=int(age[0][1]),
minutes=int(age[0][2]), seconds=int(age[0][3]))
elif len(age[0]) > 3:
_age['current'] = datetime.timedelta(days=int(age[0][0][:-1]), hours=int(age[0][1]),
minutes=int(age[0][2]), seconds=int(age[0][3]))

if len(flow.age) <= 2:
_age['current'] = datetime.timedelta(seconds=int(flow.age))
elif len(flow.age) ==4 or len(flow.age) == 5:
ms = flow.age.split(':')
_age['current'] = datetime.timedelta(minutes=int(ms[0]), seconds=int(ms[1]))
elif len(flow.age) == 7 or len(flow.age) == 8:
ms = flow.age.split(':')
_age['current'] = datetime.timedelta(hours=int(ms[0]),minutes=int(ms[1]), seconds=int(ms[2]))
else:
_age['current'] = None
'error in time format'
pattern = r'(.*)\s(.*?):(.*?):(.*)'
regex = re.compile(pattern)
age = re.findall(regex, flow.age)
_age['current'] = datetime.timedelta(days=int(age[0][0][:-1]), hours=int(age[0][1]),
minutes=int(age[0][2]), seconds=int(age[0][3]))

pattern = r'([^\s]+)'
regex = re.compile(pattern)
Expand Down

0 comments on commit f7ccae8

Please sign in to comment.