Last active
March 3, 2022 05:19
-
-
Save helpimnotdrowning/3ad4911ba39717bf041213b2df1dac47 to your computer and use it in GitHub Desktop.
(very basic) script to convert a Keptab JSON export to one compatible with Onetab. Loosely based off of a scipt that does the opposite here -> https://gist.github.com/helpimnotdrowning/d14b3e97cb20bd6aaa6dc49583979b28
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
# very basic, doesnt account for locked, pinned stuff. you are free to figure it out yourself, | |
# but this is all I need, assuming anyone ever sees this lmao | |
import json | |
import random | |
DEBUG = False | |
def write_file(file: str, content: str) -> None: | |
"""Write content to file""" | |
with open(file, 'w+') as file_: | |
file_.write(str(content)) | |
def dice() -> bool: | |
if DEBUG: | |
return random.randrange(0,500) == 47 | |
else: | |
return False | |
with open('keptab.json') as f: | |
keptab = json.load(f) | |
onetab = [] | |
counter = 0 | |
for group in keptab: | |
for tab in group['tabs']: | |
# sometimes the tab title will have an extra space at the start, this | |
# removes it. the problem comes from (i think) the OneTab -> Keptab | |
# converter on the Keptab site that doesn't strip the space after | |
# the line marker, ex. "http://a.co | Website" became " Website", | |
# not "Website" because it splits the string on the " |" part and | |
# forgetting the space afterwards (" | ") | |
title = tab['title'].strip() | |
onetab.append(abstring := f"{tab['url']} | {title}\n") | |
if dice(): | |
print(f"URL : {tab['url']}") | |
print(f"NAME: {title}") | |
print(f"INDX: {counter}") | |
print(f"FULL: {abstring}\n") | |
counter += 1 | |
# the newline separates tab groups in OneTab | |
onetab.append('\n') | |
write_file('onetab.txt', ''.join(onetab)) | |
print("All tabs written to 'onetab.txt'.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment