Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- - Export Google Reminders from Google Takeout
- - Add this script to the HTML page
- - Open the console and copy the results into a file
- - Run task import results.json
- - Recurring events are not processed, but logged for manual entry
- */
- const root = document.body.children[0];
- const KEY_RECURRENCE_INFO = 'recurrence_info';
- const KEY_CREATED_TIME = 'created_time';
- const KEY_DUE_DATE = 'due_date';
- const KEY_STATE = 'state';
- const KEY_TITLE = 'title';
- const STATE_ACTIVE = 'active';
- const STATE_ARCHIVED = 'archived';
- const STATE_UPCOMING = 'upcoming';
- function parseReminder(node) {
- const out = {};
- out.id = node.getAttribute('data-reminder-id');
- const container = node.children[0];
- let recurrence_found = false;
- for(let i = 0; i < container.children.length; i++) {
- const prop = container.children[i];
- if(prop.children[0].tagName.toLowerCase() !== 'label') throw new Error(`Expected <label>, got ${prop.children[0].tagName}`);
- const key = prop.children[0].innerHTML.toLowerCase().slice(0, -1).replace(/ /g, '_');
- const value = prop.children[1].innerHTML;
- switch(key) {
- case KEY_CREATED_TIME:
- case KEY_DUE_DATE:
- out[key] = new Date(parseInt(value));
- break;
- case KEY_RECURRENCE_INFO:
- recurrence_found = true;
- default:
- out[key] = value;
- }
- }
- if(recurrence_found) {
- console.log('Not processing:', out);
- return;
- }
- return out;
- }
- window.output = [...root.children].map(parseReminder);
- function uuidv4() {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
- return v.toString(16);
- });
- }
- let jsonOutput = '';
- for(const t of window.output) {
- if(!t) continue;
- let data = {
- uuid: uuidv4(),
- description: t.title,
- status: (function(){
- switch(t.state) {
- case 'archived':
- return 'completed';
- case 'upcoming':
- case 'active':
- return 'pending';
- default:
- throw new Error(`Unknown state: ${t.state}`);
- }
- })(),
- entry: t.created_time.toISOString().replace(/-|:|(\.\d\d\d)/g,''),
- due: t.due_date ? t.due_date.toISOString().replace(/-|:|(\.\d\d\d)/g,'') : t.created_time.toISOString().replace(/-|:|(\.\d\d\d)/g,''),
- };
- if(data.status == 'completed') {
- data.end = data.due;
- }
- jsonOutput += JSON.stringify(data) + '\n';
- }
- console.log(jsonOutput);
Add Comment
Please, Sign In to add comment