Created
November 10, 2022 15:45
-
-
Save mochki/0993fe208e7725ab4b9ce1740a233212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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