Skip to content

Instantly share code, notes, and snippets.

@mochki
Created November 10, 2022 15:45
Show Gist options
  • Save mochki/0993fe208e7725ab4b9ce1740a233212 to your computer and use it in GitHub Desktop.
Save mochki/0993fe208e7725ab4b9ce1740a233212 to your computer and use it in GitHub Desktop.
const fs = require('fs-extra');
const cal = require('./cal.js');
(async function() {
const uniq = [];
const newCal = [];
cal.map(event => {
const hash = `${event.match(/SUMMARY:(.*)\n/)[1]}::${event.match(/DTSTART(.*)\n/)[1]}`;
if (!uniq.includes(hash)) {
uniq.push(hash);
newCal.push(event);
} else {
return;
}
});
await fs.writeFile('deduped.ics', newCal.join('\n'))
})();
@mochki
Copy link
Author

mochki commented Nov 10, 2022

Get rid of duplicate events

Quick and dirty. On you ICS file, remove the top everything until you get into your first BEGIN:VEVENT and remove the last ENDCALENDAR. Use Regex to put everything between each BEGIN:VEVENT and END:VEVENT into back ticks (`). Put a comma after ever END and wrap the whole thing in []'s. import that into the index.js file. easy

Run the script. add the beginning and end of your files back on. Mostly everything should be good, except we will have lose any hardcoded '\n's and commas need to be escaped with a \ unless it doesn't becase idk. Just diff the two files and fix it yourself.

Also, it's just a shallow deduper. I look at the SUMMARY and VSTART of each event. if they're the same I count them as the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment