Guest User

Untitled

a guest
Aug 14th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. /*
  2. - Export Google Reminders from Google Takeout
  3. - Add this script to the HTML page
  4. - Open the console and copy the results into a file
  5. - Run task import results.json
  6. - Recurring events are not processed, but logged for manual entry
  7. */
  8.  
  9. const root = document.body.children[0];
  10.  
  11. const KEY_RECURRENCE_INFO = 'recurrence_info';
  12. const KEY_CREATED_TIME = 'created_time';
  13. const KEY_DUE_DATE = 'due_date';
  14. const KEY_STATE = 'state';
  15. const KEY_TITLE = 'title';
  16.  
  17. const STATE_ACTIVE = 'active';
  18. const STATE_ARCHIVED = 'archived';
  19. const STATE_UPCOMING = 'upcoming';
  20.  
  21. function parseReminder(node) {
  22. const out = {};
  23. out.id = node.getAttribute('data-reminder-id');
  24.  
  25. const container = node.children[0];
  26. let recurrence_found = false;
  27. for(let i = 0; i < container.children.length; i++) {
  28. const prop = container.children[i];
  29. if(prop.children[0].tagName.toLowerCase() !== 'label') throw new Error(`Expected <label>, got ${prop.children[0].tagName}`);
  30.  
  31. const key = prop.children[0].innerHTML.toLowerCase().slice(0, -1).replace(/ /g, '_');
  32.  
  33. const value = prop.children[1].innerHTML;
  34. switch(key) {
  35. case KEY_CREATED_TIME:
  36. case KEY_DUE_DATE:
  37. out[key] = new Date(parseInt(value));
  38. break;
  39. case KEY_RECURRENCE_INFO:
  40. recurrence_found = true;
  41. default:
  42. out[key] = value;
  43. }
  44. }
  45.  
  46. if(recurrence_found) {
  47. console.log('Not processing:', out);
  48. return;
  49. }
  50.  
  51. return out;
  52. }
  53.  
  54. window.output = [...root.children].map(parseReminder);
  55.  
  56. function uuidv4() {
  57. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  58. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  59. return v.toString(16);
  60. });
  61. }
  62.  
  63.  
  64. let jsonOutput = '';
  65. for(const t of window.output) {
  66. if(!t) continue;
  67. let data = {
  68. uuid: uuidv4(),
  69. description: t.title,
  70. status: (function(){
  71. switch(t.state) {
  72. case 'archived':
  73. return 'completed';
  74. case 'upcoming':
  75. case 'active':
  76. return 'pending';
  77. default:
  78. throw new Error(`Unknown state: ${t.state}`);
  79. }
  80. })(),
  81. entry: t.created_time.toISOString().replace(/-|:|(\.\d\d\d)/g,''),
  82. due: t.due_date ? t.due_date.toISOString().replace(/-|:|(\.\d\d\d)/g,'') : t.created_time.toISOString().replace(/-|:|(\.\d\d\d)/g,''),
  83. };
  84. if(data.status == 'completed') {
  85. data.end = data.due;
  86. }
  87.  
  88. jsonOutput += JSON.stringify(data) + '\n';
  89. }
  90.  
  91. console.log(jsonOutput);
Add Comment
Please, Sign In to add comment