Last active
June 19, 2025 23:57
-
-
Save pathikrit/2d1a6e34daa1bb9735829c5f15fd2aff to your computer and use it in GitHub Desktop.
Pocket Export
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
[{ | |
title: 'Delete all Reading List', | |
process: async () => { | |
await chrome.readingList.query({}) | |
//.then(entries => Promise.all(entries.map(entry => chrome.readingList.removeEntry({url: entry.url})))); | |
.then(entries => alert(`Deleting ${entries.length} reading list entries...`)) | |
} | |
}, | |
{ | |
title: 'Import Pocket', | |
process: async () => { | |
await chrome.readingList.query({}) | |
.then(entries => Promise.all( | |
entries.map(entry => chrome.readingList.removeEntry({url: entry.url})) | |
)); | |
const res = await fetch('http://localhost:8005/pocket.jsonl'); | |
const text = await res.text() | |
const lines = text.split('\n').filter(Boolean); | |
let i = 0; | |
for (const raw of lines) { | |
if (i % 100 === 0) { | |
console.log(`Processing ${i}th item...`); | |
} | |
i++; | |
const item = JSON.parse(raw) | |
const url = item.given_url || item.resolved_url | |
const title = item.given_title || item.resolved_title || url | |
const hasBeenRead = item.time_read !== "0" | |
if (hasBeenRead) continue | |
if (url && title) { | |
await chrome.readingList | |
.addEntry({title, url, hasBeenRead}) | |
//.then(() => console.log(`Imported url=${url}`)) | |
.catch(err => console.error(`Error importing url=${url}`, err)) | |
} else { | |
console.warn(`Skipping item with missing URL or title: ${raw}`) | |
} | |
} | |
} | |
} | |
] |
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
for f in *.jsonl; do [ -s "$f" ] && { cat "$f"; echo; }; done > pocket.jsonl2 |
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
import requests | |
import time | |
import json | |
from tenacity import retry, stop_after_attempt, wait_exponential | |
ACCESS_TOKEN = ??? | |
CONSUMER_KEY = ??? | |
BATCH_SIZE = 100 | |
start_page = 0 | |
@retry(stop=stop_after_attempt(5), wait=wait_exponential()) | |
def more(): | |
offset = start_page * BATCH_SIZE | |
resp = requests.post( | |
url='https://getpocket.com/v3/get', | |
json={ | |
'consumer_key': CONSUMER_KEY, | |
'access_token': ACCESS_TOKEN, | |
'state': 'all', | |
'detailType': 'simple', | |
'sort': 'oldest', | |
'count': BATCH_SIZE, | |
'offset': offset | |
}, | |
headers={'X-Accept': 'application/json'} | |
) | |
resp.raise_for_status() | |
batch = list(resp.json().get('list', {}).values()) | |
print(f"Fetched {len(batch)} items @ {offset=}") | |
return batch | |
while True: | |
items = more() | |
with open(f"pocket-{start_page}.jsonl", 'w') as file: | |
output = [json.dumps(item) for item in items] | |
file.write("\n".join(output)) | |
if len(items) < BATCH_SIZE: | |
break | |
start_page += 1 | |
time.sleep(0.5) # be polite |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment