See http://fokkezb.nl/2015/01/13/how-to-restore-a-deleted-icloud-calendar/
Last active
August 29, 2015 14:13
-
-
Save FokkeZB/617f32dcde946395f2f5 to your computer and use it in GitHub Desktop.
Preparing restored iCloud Calendar Events to be imported in a new Calendar
This file contains hidden or 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
var fs = require('fs'), | |
path = require('path'); | |
var glob = require('glob'), | |
uuid = require('node-uuid'); | |
var input = process.argv[2] || ''; | |
var output = process.argv[3] || ''; | |
fs.exists(input, function it(exists) { | |
if (!exists) { | |
console.error('Input path not found: ' + input); | |
} else { | |
fs.exists(output, function it(exists) { | |
if (!exists) { | |
console.error('Output path not found: ' + output); | |
} else { | |
glob('**/*.ics', { | |
cwd: input | |
}, function handle(err, files) { | |
if (err) { | |
console.error(err); | |
} else { | |
files.forEach(function forEach(file, fileNr) { | |
var inputFilePath = path.join(input, file); | |
fs.readFile(inputFilePath, 'utf8', function handle(err, inputData) { | |
if (err) { | |
console.error(inputFilePath + ': ' + err); | |
} else { | |
var outputFilePath = path.join(output, path.basename(file)); | |
var inputLines = inputData.split('\r\n'); | |
var outputLines = []; | |
inputLines.forEach(function forEach(inputLine, index) { | |
var outputLine; | |
if (inputLine.substr(0, 2) === 'X-') { | |
return; | |
} else { | |
var parts = inputLine.split(':'); | |
if (parts[0] === 'UID') { | |
var newUid = uuid.v4().toUpperCase(); | |
if (path.basename(file) === parts[1] + '.ics') { | |
outputFilePath = path.join(output, newUid + '.ics'); | |
} | |
parts[1] = newUid; | |
inputLine = parts.join(':'); | |
} | |
if (outputLine) { | |
console.log(inputLine + ' > ' + outputLine); | |
outputLines.push(outputLine); | |
} else { | |
outputLines.push(inputLine); | |
} | |
} | |
}); | |
var outputData = outputLines.join('\r\n'); | |
// console.log(inputFilePath); | |
// console.log(inputData); | |
// console.log(outputFilePath); | |
// console.log(outputData); | |
fs.writeFile(outputFilePath, outputData, function(err) { | |
if (err) { | |
console.error(inputFilePath + ': ' + err); | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
}); |
This file contains hidden or 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
{ | |
"name": "ics", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "MIT", | |
"dependencies": { | |
"glob": "^4.3.3", | |
"node-uuid": "^1.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't get node.js to work, so I rewrote this in Python. Thanks for the article; I have no idea how I deleted my calendar, but i was an important one, and this worked perfectly!