Hi folks,
I’m trying to send many x-callback requests in a rowto Fantastical, in order to bulk import events into a calendar after doing some planning Drafts. My script looks like this:
const baseURL = "x-fantastical3://parse";
const category_regex = /^\#\s?\w+/
var category = ''
const day_regex = /^\#\#\s?\w+/
var day = ''
const task_regex = /^\-\s?.+/
var task = ''
const replace_regex = /^[#-]+\s?/
for (var line of draft.lines) {
if (category_regex.test(line)) {
category = line.replace(replace_regex,'');
} else if (day_regex.test(line)) {
day = line.replace(replace_regex,'');
} else if (task_regex.test(line)) {
task = line.replace(replace_regex,'');
parsed_line = category + ': ' + task + ' on ' + day;
console.log(parsed_line);
var cb = CallbackURL.create();
cb.baseURL = baseURL;
cb.addParameter("add", 1);
cb.addParameter("s", parsed_line);
cb.open();
}
}
and my input text looks like this
#research
## Wednesday
- make some notes
## Thursday
- write some text
- fix some bugs
## Friday
# teaching
## Friday
- teach some students
But the looping, as currently structured, is really slow, even on these four x-callback-url calls. I’ve tried not waiting for a request, but this seems to create a race condition that only actually creates the most recently seen parsed line in Fantastical.
Anyone have any suggestions? Somehow this is really slow, the “Event in Fantastical” action (which uses a single CallbackURL action) seems to be really fast.