Advertisement
Guest User

Untitled

a guest
Sep 10th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import time, json
  2. from urllib.parse import urlparse, urlunparse
  3.  
  4. class tab:
  5.     def __init__(self, url, title):
  6.         self.url = url; self.title = title
  7.         self.favIconUrl = urlunparse(urlparse(url)._replace(path='favicon.ico',params='',query='',fragment=''))
  8.         self.pinned = False; self.muted = False
  9.  
  10. _id, res, tabs, urls = int(time.time() * 1000), [], [], []
  11.  
  12. lines = open('onetab.txt').readlines()
  13. for ln in lines:
  14.     if ln is '\n':
  15.         _id = _id - 60000
  16.         res.append({
  17.             "_id": _id, "time": _id,
  18.             "title": "", "tags": [],
  19.             "tabs": tabs, "urls": urls,
  20.             "lock": False, "star": False
  21.         })
  22.         tabs, urls = [], []
  23.         continue
  24.  
  25.     token = ln.strip().split('|', 2)
  26.     url, title = token[0].strip(), '|'.join(token[1:])
  27.  
  28.     t = tab(url, title)
  29.     tabs.append(t.__dict__)
  30.     urls.append(url)
  31.  
  32. _id = _id - 60000
  33. res.append({
  34.             "_id": _id, "time": _id,
  35.             "title": "", "tags": [],
  36.             "tabs": tabs, "urls": urls,
  37.             "lock": False, "star": False
  38.         })
  39.  
  40. with open('onetab.json', 'w') as f:
  41.     json.dump(res, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement