├── images ├── overview_1.png ├── overview_2.png ├── overview_3.png └── notebook_iphone.png ├── config.php ├── LICENSE ├── README.md └── import_kindle_notebook_to_notion.php /images/overview_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/import-kindle-notebook-to-notion/master/images/overview_1.png -------------------------------------------------------------------------------- /images/overview_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/import-kindle-notebook-to-notion/master/images/overview_2.png -------------------------------------------------------------------------------- /images/overview_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/import-kindle-notebook-to-notion/master/images/overview_3.png -------------------------------------------------------------------------------- /images/notebook_iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/import-kindle-notebook-to-notion/master/images/notebook_iphone.png -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | 21 | git clone https://github.com/happy-se-life/import-kindle-notebook-to-notion.git 22 | 23 | 24 | ## Preparation 25 | 26 | 1. Create Reading list page. See screenshot. 27 | 28 | 29 | 2. Edit config.php, set API token and database ID. 30 | * ref. https://developers.notion.com/docs 31 | 32 | 3. Share a database with your integration. 33 | * ref. https://developers.notion.com/docs 34 | 35 | ## How to use 36 | 37 | 1. Read book using kindle app and make notebook. 38 | 39 | 40 | 2. Export notebook as html. Save html to above folder. 41 | 42 | 3. Run this tool. 43 |
44 | php import-kindle-notebook-to-notion.php notebook.html
45 | 
46 | 47 | ## Screenshot after import 48 | 49 | 1. Database 50 | 51 | 52 | 2. Individual page 53 | 54 | 55 | ## License 56 | * MIT Lisense 57 | 58 | ## Notes 59 | * Personal use only. -------------------------------------------------------------------------------- /import_kindle_notebook_to_notion.php: -------------------------------------------------------------------------------- 1 | "block", 23 | "type" => "$type", 24 | "$type" => [ 25 | "text" => [ 26 | [ 27 | "type" => "text", 28 | "text" => [ "content" => "$content" ] 29 | ] 30 | ] 31 | ] 32 | ]; 33 | } 34 | 35 | /** 36 | * Create post data. 37 | */ 38 | function createPostData($html) { 39 | if (!is_file($html)) { 40 | echo "Please specify the correct file.\n"; 41 | exit(1); 42 | } 43 | 44 | // Read html 45 | $doc = new DOMDocument(); 46 | $doc->loadHTMLFile($html); 47 | $elements = $doc->getElementsByTagName('div'); 48 | 49 | $children = []; 50 | $bookTitle = []; 51 | $authors = []; 52 | 53 | // Create children array contained in post_data 54 | foreach ($elements as $elm) { 55 | $text = trim($elm->nodeValue); 56 | switch ($elm->getAttribute('class')) { 57 | case "bookTitle" : 58 | $bookTitle = $text; 59 | break; 60 | case "authors" : 61 | $authors = $text; 62 | break; 63 | case "citation" : 64 | if (strlen($text) != 0) { 65 | $children[] = getArrayBlock("paragraph", $text); 66 | } 67 | break; 68 | case "sectionHeading" : 69 | $children[] = getArrayBlock("heading_2", $text); 70 | break; 71 | case "noteHeading" : 72 | $children[] = getArrayBlock("heading_3", $text); 73 | break; 74 | case "noteText" : 75 | $children[] = getArrayBlock("paragraph", $text); 76 | break; 77 | default : 78 | break; 79 | } 80 | } 81 | 82 | // Create post data 83 | $post_data = [ 84 | "parent" => [ "database_id" => MY_NOTION_DATABASE_ID ], 85 | "properties" => [ 86 | "Name" => [ 87 | "title" => [ 88 | [ 89 | "text" => [ 90 | "content" => "$bookTitle" 91 | ] 92 | ] 93 | ] 94 | ], 95 | "Authors" => [ 96 | "rich_text" => [ 97 | [ 98 | "text" => [ 99 | "content" => "$authors" 100 | ] 101 | ] 102 | ] 103 | ] 104 | ], 105 | "children" => $children, 106 | ]; 107 | 108 | return $post_data; 109 | } 110 | 111 | /** 112 | * Import to notion. 113 | */ 114 | function import($html) { 115 | 116 | $post_data = createPostData($html); 117 | 118 | $header = [ 119 | "Authorization: Bearer " . MY_NOTION_TOKEN, 120 | "Content-Type: application/json", 121 | "Notion-Version: " . NOTION_API_VERSION, 122 | ]; 123 | 124 | $curl = curl_init( NOTION_API_ENDPOINT ); 125 | 126 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 127 | curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 128 | curl_setopt($curl, CURLOPT_POST, TRUE); 129 | curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($post_data)); 130 | 131 | // Post 132 | $result = curl_exec($curl); 133 | 134 | if ($result) { 135 | echo "The import process was successful.\n"; 136 | } else { 137 | echo "Import process failed.\n"; 138 | } 139 | 140 | return; 141 | } 142 | 143 | import($argv[1]); 144 | --------------------------------------------------------------------------------