enhancements

This commit is contained in:
David Barroso committed 2015-05-28 17:06:10 -04:00
1 parent 20d0386693
commit a155651e9a
1 file changed
+5 -4
+5 -4
View File
@@ -65,15 +65,14 @@ def convert_uptime_string_seconds(uptime):
Convert uptime strings to seconds. The string can be formatted various ways, eg. Convert uptime strings to seconds. The string can be formatted various ways, eg.
1 hour, 56 minutes 1 hour, 56 minutes
''' '''
regex_1 = re.compile(r"((?P<days>\d+) day(s)?,\s+)?((?P<hours>\d+) hour(s)?,\s+)?((?P<minutes>\d+) minute(s)?)") regex_1 = re.compile(r"((?P<weeks>\d+) week(s)?,\s+)?((?P<days>\d+) day(s)?,\s+)?((?P<hours>\d+) hour(s)?,\s+)?((?P<minutes>\d+) minute(s)?)")
regex_2 = re.compile(r"((?P<hours>\d+)):((?P<minutes>\d+)):((?P<seconds>\d+))") regex_2 = re.compile(r"((?P<hours>\d+)):((?P<minutes>\d+)):((?P<seconds>\d+))")
regex_list = [regex_1, regex_2] regex_list = [regex_1, regex_2]
# say whaaaat!?
uptime_dict = dict() uptime_dict = dict()
for regex in regex_list: for regex in regex_list:
uptime_dict = regex.match(uptime) uptime_dict = regex.search(uptime)
if uptime_dict is not None: if uptime_dict is not None:
uptime_dict = uptime_dict.groupdict() uptime_dict = uptime_dict.groupdict()
break break
@@ -83,7 +82,9 @@ def convert_uptime_string_seconds(uptime):
for unit, value in uptime_dict.iteritems(): for unit, value in uptime_dict.iteritems():
if value != None: if value != None:
if unit == 'days': if unit == 'weeks':
uptime_seconds += int(value) * 604800
elif unit == 'days':
uptime_seconds += int(value) * 86400 uptime_seconds += int(value) * 86400
elif unit == 'hours': elif unit == 'hours':
uptime_seconds += int(value) * 3600 uptime_seconds += int(value) * 3600