I'm using dateutil to generate a schedule based on an input file.
my config file looks like this:
[alarm1]
time = 8:00
days = MO
[alarm2]
time = 9:00
days = TU, WE
[alarm3]
time = 22:00
days = MO, WE, FR
etc..
I'm using dateutil to generate a schedule based off this.
here's some sample code, where I omitted the control flows and import code for the sake of brevity.
from dateutil.rrule import *
from dateutil.parser import *
import datetime
import configparser
alarms = rruleset()
time = parse(alarm_parser.get(alarm_section, 'time')).time()
date = datetime.date.today()
alarm_time= datetime.datetime.combine(date, time)
days = '(' + alarm_parser.get(alarm_section, 'days') + ',)'
alarm_days = eval(days)
alarms.rrule(rrule(WEEKLY, dtstart = alarm_datetime, byweekday = alarm_days, count = 1))
this code now works thanks to eval However, eval apparently risky.
I've tried rrulestr(), but the command doesn't seem to accept byweekday = as part of the argument.
how do I convert the string in the config file to a tuple that rrule can work with without using eval? I've tried ast.literal_eval, but that gives me the following error
ValueError: malformed node or string: <_ast.Name object at 0xb68e2430>