Skip to content

Commit

Permalink
Update main.py. Fix timedelta weeks detection
Browse files Browse the repository at this point in the history
  • Loading branch information
knewell committed Apr 10, 2019
1 parent 3d67405 commit 3d15275
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def modFlowRoute(self, flowRouteData=None):
env = Environment(autoescape=False,
loader=FileSystemLoader('./template'), trim_blocks=False, lstrip_blocks=False)
template = env.get_template('mod-flow-route.conf')
print template.render(flowRouteData)
#print(template.render(flowRouteData))

my_router = None
for router in self.routers:
Expand Down Expand Up @@ -218,11 +218,19 @@ def getActiveFlowRoutes(self):
_age['current'] = datetime.timedelta(hours=int(ms[0]), minutes=int(ms[1]),
seconds=int(ms[2]))
else:
pattern = r'(.*)\s(.*?):(.*?):(.*)'
pattern = r'(.*w)?(.*)\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]))
if age[0][0][:-1] is '':
weeks = 0
else:
weeks = int(age[0][0][:-1])
_age['current'] = datetime.timedelta(
weeks=weeks,
days=int(age[0][1][:-1]),
hours=int(age[0][2]),
minutes=int(age[0][3]),
seconds=int(age[0][4]))

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

0 comments on commit 3d15275

Please sign in to comment.