Skip to content

Instantly share code, notes, and snippets.

@xunzhou
Last active March 2, 2022 06:32
Show Gist options
  • Save xunzhou/e90fecc37386531a02cc671626dc4800 to your computer and use it in GitHub Desktop.
Save xunzhou/e90fecc37386531a02cc671626dc4800 to your computer and use it in GitHub Desktop.
Translate Onetab txt export → Keptab json import
import time, json
from urllib.parse import urlparse, urlunparse
class tab:
def __init__(self, url, title):
self.url = url; self.title = title
self.favIconUrl = urlunparse(urlparse(url)._replace(path='favicon.ico',params='',query='',fragment=''))
self.pinned = False; self.muted = False
_id, res, tabs, urls = int(time.time() * 1000), [], [], []
lines = open('onetab.txt').readlines()
lines.append('\n')
for ln in lines:
if ln is '\n':
_id = _id - 60000
res.append({
"_id": _id, "time": _id,
"title": "", "tags": [],
"tabs": tabs, "urls": urls,
"lock": False, "star": False
})
tabs, urls = [], []
continue
token = ln.strip().split('|', 2)
url, title = token[0].strip(), '|'.join(token[1:])
t = tab(url, title)
tabs.append(t.__dict__)
urls.append(url)
with open('keptab.json', 'w') as f:
json.dump(res, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment