Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks on the data structure/event before/after event_from_yaml #44

Open
rkdarst opened this issue Dec 7, 2022 · 5 comments
Open

Hooks on the data structure/event before/after event_from_yaml #44

rkdarst opened this issue Dec 7, 2022 · 5 comments

Comments

@rkdarst
Copy link
Contributor

rkdarst commented Dec 7, 2022

I'd be interested in a way to run hooks on the event_yaml (= loaded data structures) and event at the start/end of event_from_yaml. Would you like that feature here, and if so, do you have any suggestions for implementing it? If you would like it, I can try an initial implementation (the only major problem is "how to pass arguments into there - do we carry around hooks between all the functions, or make something global?").

My alternative option is to monkey-patch hooks in, but something clean+supported would be better... if we can find it.

(in this case, I would like to have a way to have a description_suffix that would be appended to the description. This would make template events with &label and <<: *label) cleaner... but I expect that hooks would be better than making yaml2ics too specific to my needs...

@stefanv
Copy link
Member

stefanv commented Dec 7, 2022

Hi Richard, that could make sense. Are you thinking adding this as an argument when invoking yaml2ics as a script? And it gets the event as a string and returns it as a string?

@rkdarst
Copy link
Contributor Author

rkdarst commented Dec 7, 2022

Hm, interesting idea... I didn't think of that. So far I was just thinking through the Python API, since that's how I use it (but python API should come first anyway).

Since my entry point is files_to_calendar, to do it via arguments, the arguments would have to be passed to files_to_events and then event_from_yaml. Writing this out, I'm less confident that I can think of any maintainable way to adding this to yaml2ics, and might want to do this via monkey patching

Or... what would you say about adding a config argument to all functions, defaulting to {}, and adding hooks into there? That might be simple and elegant enough.

@stefanv
Copy link
Member

stefanv commented Dec 7, 2022

What should the hooks do, just so I can form an idea around what's needed?

@rkdarst
Copy link
Contributor Author

rkdarst commented Dec 8, 2022

in this case my hook would be:

if 'description_suffix' in event_data:
    event_data['description'] = '\n\n'.join(event_data['description'], event_data.pop('description_suffix'))

... and maybe the equivalent for description_prefix. Even though it seems trivial, with the templating(inheritance?) in yaml I describe above, I can easily avoid repetition when making a lot of similar events.

... of course I could directly add this. On second thought, maybe it's useful for more people (except that the yaml templating isn't included in examples, I think...)

@stefanv
Copy link
Member

stefanv commented Jun 8, 2023

Perhaps the easiest would be:

all_events, name = files_to_events(files)
[... custom postprocessing ...]
calendar = events_to_calendar(all_events)

Would that work for your use-case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants