multiple ranges support

This commit is contained in:
tyler 2023-09-16 16:55:12 -04:00
parent f47a7005cf
commit c8e55528b8
2 changed files with 19 additions and 16 deletions

View file

@ -14,10 +14,10 @@ The scheduling options are:
|:-------------|:-----------------------------------------------------------------------------------------------------------|:---------------------------------------------------|:-------------------------------------------------------------|
| Hourly | Update only when the script is run in that hour or hour range | hourly(Hour of Day)<br>hourly(Start Hour-End Hour) | `hourly(17)`<br>`hourly(17-04)` |
| Daily | Update once a day | daily | `daily` |
| Weekly | Update once a week on the specified days (For multiple days use a bar-separated (<code>&#124;</code>) list | weekly(Days of Week) | `weekly(sunday)`<br><code>weekly(sunday&#124;tuesday)</code> |
| Weekly | Update once a week on the specified days (For multiple days, use a bar-separated (<code>&#124;</code>) list)| weekly(Days of Week) | `weekly(sunday)`<br><code>weekly(sunday&#124;tuesday)</code> |
| Monthly | Update once a month on the specified day | monthly(Day of Month) | `monthly(1)` |
| Yearly | Update once a year on the specified day | yearly(MM/DD) | `yearly(01/30)` |
| Range | Updates whenever the date is within the range | range(MM/DD-MM/DD) | `range(12/01-12/31)` |
| Range | Updates whenever the date is within the range (For mulitple ranges, use a bar-separated (`\|`) list) | range(MM/DD-MM/DD) | `range(12/01-12/31)`<br>`range(8/01-8/15\|9/01-9/15)` |
| Never | Never updates | never | `never` |
| Non Existing | Updates if it doesn't exist | non_existing | `non_existing` |
| All | Requires that all comma separated scheduling options inside its brackets be meet in order to run | all[Options] | `all[weekly(sunday), hourly(17)]` |

View file

@ -669,20 +669,23 @@ def schedule_check(attribute, data, current_time, run_hour, is_all=False):
except ValueError:
logger.error(f"Schedule Error: yearly {display} must be in the MM/DD format i.e. yearly(11/22)")
elif run_time.startswith("range"):
match = re.match("^(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])-(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])$", param)
if not match:
logger.error(f"Schedule Error: range {display} must be in the MM/DD-MM/DD format i.e. range(12/01-12/25)")
continue
month_start, day_start = check_day(int(match.group(1)), int(match.group(2)))
month_end, day_end = check_day(int(match.group(3)), int(match.group(4)))
month_check, day_check = check_day(current_time.month, current_time.day)
check = datetime.strptime(f"{month_check}/{day_check}", "%m/%d")
start = datetime.strptime(f"{month_start}/{day_start}", "%m/%d")
end = datetime.strptime(f"{month_end}/{day_end}", "%m/%d")
range_collection = True
schedule_str += f"\nScheduled between {pretty_months[month_start]} {num2words(day_start, to='ordinal_num')} and {pretty_months[month_end]} {num2words(day_end, to='ordinal_num')}"
if start <= check <= end if start < end else (check <= end or check >= start):
all_check += 1
ok_ranges = param.lower().split("|")
err = None
for ok_range in ok_ranges:
match = re.match("^(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])-(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])$", ok_range)
if not match:
logger.error(f"Schedule Error: range {display} must be in the MM/DD-MM/DD format i.e. range(12/01-12/25)")
continue
month_start, day_start = check_day(int(match.group(1)), int(match.group(2)))
month_end, day_end = check_day(int(match.group(3)), int(match.group(4)))
month_check, day_check = check_day(current_time.month, current_time.day)
check = datetime.strptime(f"{month_check}/{day_check}", "%m/%d")
start = datetime.strptime(f"{month_start}/{day_start}", "%m/%d")
end = datetime.strptime(f"{month_end}/{day_end}", "%m/%d")
range_collection = True
schedule_str += f"\nScheduled between {pretty_months[month_start]} {num2words(day_start, to='ordinal_num')} and {pretty_months[month_end]} {num2words(day_end, to='ordinal_num')}"
if start <= check <= end if start < end else (check <= end or check >= start):
all_check += 1
else:
logger.error(f"Schedule Error: {display}")
if is_all: