Skip to content

Instantly share code, notes, and snippets.

@helpimnotdrowning
Forked from xunzhou/trans.py
Last active March 2, 2022 06:34
Show Gist options
  • Save helpimnotdrowning/d14b3e97cb20bd6aaa6dc49583979b28 to your computer and use it in GitHub Desktop.
Save helpimnotdrowning/d14b3e97cb20bd6aaa6dc49583979b28 to your computer and use it in GitHub Desktop.
Translate Onetab txt export → Keptab json import (by @xunzhou )
import time
import 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