Skip to content

Instantly share code, notes, and snippets.

@svanellewee
Created February 7, 2017 06:54
Show Gist options
  • Save svanellewee/c655cab3ff9adf2e2fec7b6a3668350d to your computer and use it in GitHub Desktop.
Save svanellewee/c655cab3ff9adf2e2fec7b6a3668350d to your computer and use it in GitHub Desktop.
Cronread
import re
entries = (entry for entry in lst[1:])
lookup = ["Sundays",
"Mondays",
"Tuesdays",
"Wednesdays",
"Thursdays",
"Fridays",
"Saturdays",
"Sundays"]
def interpret_cron(string):
results = string.split()
minute, hour, day_month, month, day_week = results
time = "{}h{}".format(hour, minute)
if day_month != "*":
raise NotImplementedError("not handling this")
if month != "*":
raise NotImplementedError("not doing this")
result_string = "{}".format(time)
day_range = ["{} to {}".format(lookup[int(start)], lookup[int(stop)]) for start, stop in re.findall("(\d+)-(\d+)", day_week)]
days = ", ".join(lookup[int(value)] for value in re.findall("(\d+)", day_week))
if day_range:
result_string += " {}".format(day_range[0])
elif day_week == '*':
result_string += " Every day"
elif days:
result_string += " {}".format(days)
else:
result_string += " {}".format(lookup[int(day_week)])
return result_string
#return results
crons = ((name, interpret_cron(cron), cron) for cron, name in entries)
for name, cron, original_cron in crons:
print("|{}|{}|{}|".format(original_cron, name, cron))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment