Allow different time ranges for the different sources.
This commit is contained in:
parent
264301ecc0
commit
c892ac1aab
1 changed files with 15 additions and 5 deletions
20
main.py
20
main.py
|
@ -45,6 +45,16 @@ def range_str_to_timedelta(value):
|
||||||
weeks=values['w']
|
weeks=values['w']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def multiple_timedeltas(value):
|
||||||
|
mappings = {}
|
||||||
|
for v in value.split(','):
|
||||||
|
kv = v.split(':')
|
||||||
|
if len(kv) == 1:
|
||||||
|
mappings[-1] = range_str_to_timedelta(kv[0])
|
||||||
|
continue
|
||||||
|
mappings[int(kv[0])] = range_str_to_timedelta(kv[1])
|
||||||
|
return mappings
|
||||||
|
|
||||||
config_schema = Schema({
|
config_schema = Schema({
|
||||||
'sources': [dict],
|
'sources': [dict],
|
||||||
'sinks': [dict],
|
'sinks': [dict],
|
||||||
|
@ -52,12 +62,12 @@ config_schema = Schema({
|
||||||
Optional('level', default=':WARNING,wp_cal:INFO'): Use(str),
|
Optional('level', default=':WARNING,wp_cal:INFO'): Use(str),
|
||||||
},
|
},
|
||||||
Optional('range', default='365d'): Or(
|
Optional('range', default='365d'): Or(
|
||||||
|
dict,
|
||||||
And(
|
And(
|
||||||
Use(str),
|
Use(str),
|
||||||
Regex(r'[0-9]+[smhdw]'),
|
Regex(r'(([0-9]+:)?[0-9]+[smhdw],?)*'),
|
||||||
Use(range_str_to_timedelta),
|
Use(multiple_timedeltas),
|
||||||
),
|
),
|
||||||
lambda x: isinstance(x, datetime.timedelta)
|
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -149,9 +159,9 @@ def main(config, dryrun, level, range):
|
||||||
# gather events
|
# gather events
|
||||||
events = []
|
events = []
|
||||||
source_results = []
|
source_results = []
|
||||||
for source in sources:
|
for i, source in enumerate(sources):
|
||||||
try:
|
try:
|
||||||
events += source.get_events_resolved(until=config['range'])
|
events += source.get_events_resolved(until=config['range'].get(i, config['range'][-1]))
|
||||||
source_results += [True]
|
source_results += [True]
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception('failed to get events from source %s', source)
|
logger.exception('failed to get events from source %s', source)
|
||||||
|
|
Loading…
Reference in a new issue