-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
850 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ | ||
*.html |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Pocket importer | ||
|
||
Imports Pocket saves into Bookmd. | ||
|
||
**Disclaimer:** Use at your own risk, no guarantees whatsoever. I've used it to migrate my own Pocket saves and it worked fine except for a few websites. | ||
|
||
## Usage | ||
|
||
This currently only works with Chrome. Before running, make sure you have Chrome installed and that it is in your PATH. | ||
|
||
### Export from Pocket | ||
|
||
Open the [Pocket Export](https://getpocket.com/export) page and click on "Export HTML file" link. Copy the file to the `pocket-importer` directory as `pocket-export.html`. | ||
|
||
### Run server | ||
|
||
From the root of the `bookmd` project, run | ||
|
||
```shell | ||
make | ||
bin/server | ||
``` | ||
|
||
### Run Chrome in debug mode | ||
|
||
```shell | ||
/path/to/chrome --remote-debugging-port=1243 | ||
``` | ||
|
||
Playwright [cannot currently deal with 'open in app' dialogs](https://github.com/microsoft/playwright/issues/11014), so we have to ensure they are dismissed: to do so, type `obsidian://` in the address bar, tick the checkbox of the dialog so that it won't show up again, and select `Open in Obsidian`. | ||
|
||
### Run the importer | ||
|
||
From the `pocket-importer` directory, run | ||
|
||
```shell | ||
npm install | ||
npx tsx ./importer.ts | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {chromium} from 'playwright'; | ||
import * as nhp from 'node-html-parser'; | ||
import * as fs from "node:fs"; | ||
|
||
(async () => { | ||
const browser = await chromium.connectOverCDP('http://localhost:1243'); | ||
const defaultContext = browser.contexts()[0]; | ||
const page = defaultContext.pages()[0]; | ||
|
||
const serverAddress = 'http://localhost:3333'; | ||
const vault = 'my-vault'; | ||
const folder = 'Clippings'; | ||
const doc = fs.readFileSync('./pocket-export.html', 'utf8'); | ||
const root: nhp.HTMLElement = nhp.parse(doc); | ||
|
||
const links = root.querySelectorAll('a').map( | ||
(a: nhp.HTMLElement): { url: string, link: string } => { | ||
const tags = a.getAttribute('tags') | ||
.split(",") | ||
.map(tag => 'tag=' + encodeURIComponent(tag.trim())) | ||
.join("&"); | ||
|
||
const params = [ | ||
`url=${encodeURIComponent(a.getAttribute('href'))}`, | ||
`vault=${encodeURIComponent(vault)}`, | ||
`folder=${encodeURIComponent(folder)}`, | ||
`epoch=${a.getAttribute('time_added')}`, | ||
'silent=true', | ||
tags | ||
].join('&') | ||
|
||
return {url: a.getAttribute('href'), link: `${serverAddress}/api/bookmarks?${params}`} | ||
} | ||
); | ||
|
||
for (const {url, link} of links) { | ||
try { | ||
await page.goto(link); | ||
} catch (err) { | ||
if (err instanceof Error && !err.message.startsWith('page.goto: net::ERR_ABORTED')) { | ||
console.log('failed to open', url, err.name); | ||
} | ||
} | ||
} | ||
await browser.close(); | ||
})(); |
Oops, something went wrong.