-
-
Save helpimnotdrowning/d14b3e97cb20bd6aaa6dc49583979b28 to your computer and use it in GitHub Desktop.
Translate Onetab txt export → Keptab json import (by @xunzhou )
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 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