|
| 1 | +import json |
| 2 | +import datetime |
| 3 | +import uuid |
| 4 | + |
| 5 | +def unix_timestamp(dt): |
| 6 | + # Windows/Chrome timestamp (microseconds since Jan 1, 1601) |
| 7 | + return int((dt - datetime.datetime(1601, 1, 1)).total_seconds() * 1000000) |
| 8 | + |
| 9 | +themes = { |
| 10 | + "Tech & Programming": ["github", "programming", "docker", "server", "code", "dev", "tech", "node", "python", "rust", "npm", "stack", "api", "web", "cloud", "aws", "google", "microsoft", "apple", "app", "software"], |
| 11 | + "Linux & OS": ["fedora", "linux", "ubuntu", "debian", "kernel", "cli", "shell", "bash", "terminal", "desktop", "os", "system", "config"], |
| 12 | + "News & Finance": ["news", "breaking", "msn", "trump", "politics", "economy", "market", "finance", "bank", "money", "stock", "crypto", "bitcoin", "business", "invest", "trading"], |
| 13 | + "Psychology & Growth": ["psychology", "mental", "self", "growth", "happiness", "manipulation", "relationships", "advice", "life", "wellness", "mindset", "success", "productivity"], |
| 14 | + "Art, Culture & Design": ["art", "artist", "design", "museum", "culture", "style", "creative", "photo", "music", "history", "philosophy", "books", "writing"], |
| 15 | + "Lifestyle & Health": ["food", "cooking", "recipe", "health", "fitness", "yoga", "travel", "holiday", "home", "garden", "shopping", "amazon", "buy", "deal"], |
| 16 | + "Education & Career": ["learn", "course", "study", "university", "school", "job", "career", "resume", "cv", "interview", "skills", "training"], |
| 17 | + "Media & Social": ["youtube", "video", "tv", "movie", "entertainment", "facebook", "twitter", "x.com", "instagram", "reddit", "watch", "podcast"] |
| 18 | +} |
| 19 | + |
| 20 | +def categorize(line): |
| 21 | + line_lower = line.lower() |
| 22 | + for theme, keywords in themes.items(): |
| 23 | + if any(keyword in line_lower for keyword in keywords): |
| 24 | + return theme |
| 25 | + return "Uncategorized" |
| 26 | + |
| 27 | +all_bookmarks = {} |
| 28 | + |
| 29 | +try: |
| 30 | + with open("/tmp/firefox_bookmarks.txt", "r") as f: |
| 31 | + for line in f: |
| 32 | + theme = categorize(line) |
| 33 | + all_bookmarks.setdefault(theme, []).append(line.strip()) |
| 34 | + |
| 35 | + with open("/tmp/edge_bookmarks.txt", "r") as f: |
| 36 | + for line in f: |
| 37 | + theme = categorize(line) |
| 38 | + all_bookmarks.setdefault(theme, []).append(line.strip()) |
| 39 | + |
| 40 | + new_roots = { |
| 41 | + "bookmark_bar": { |
| 42 | + "children": [], |
| 43 | + "date_added": str(unix_timestamp(datetime.datetime.now())), |
| 44 | + "date_last_used": "0", |
| 45 | + "guid": str(uuid.uuid4()), |
| 46 | + "id": "1", |
| 47 | + "name": "Favorites Bar", |
| 48 | + "type": "folder" |
| 49 | + }, |
| 50 | + "other": { "children": [], "date_added": "0", "date_last_used": "0", "guid": str(uuid.uuid4()), "id": "2", "name": "Other Favorites", "type": "folder" }, |
| 51 | + "synced": { "children": [], "date_added": "0", "date_last_used": "0", "guid": str(uuid.uuid4()), "id": "3", "name": "Mobile Favorites", "type": "folder" } |
| 52 | + } |
| 53 | + |
| 54 | + current_id = 4 |
| 55 | + sorted_themes = sorted([t for t in all_bookmarks.keys() if t != "Uncategorized"]) + ["Uncategorized"] |
| 56 | + |
| 57 | + for theme in sorted_themes: |
| 58 | + if theme in all_bookmarks: |
| 59 | + unique_items = sorted(list(set(all_bookmarks[theme]))) |
| 60 | + folder = { |
| 61 | + "date_added": str(unix_timestamp(datetime.datetime.now())), |
| 62 | + "date_last_used": "0", |
| 63 | + "guid": str(uuid.uuid4()), |
| 64 | + "id": str(current_id), |
| 65 | + "name": theme, |
| 66 | + "type": "folder", |
| 67 | + "children": [] |
| 68 | + } |
| 69 | + current_id += 1 |
| 70 | + for item in unique_items: |
| 71 | + parts = item.split("|") |
| 72 | + if len(parts) == 2: |
| 73 | + folder["children"].append({ |
| 74 | + "date_added": str(unix_timestamp(datetime.datetime.now())), |
| 75 | + "date_last_used": "0", |
| 76 | + "guid": str(uuid.uuid4()), |
| 77 | + "id": str(current_id), |
| 78 | + "name": parts[0], |
| 79 | + "type": "url", |
| 80 | + "url": parts[1] |
| 81 | + }) |
| 82 | + current_id += 1 |
| 83 | + new_roots["bookmark_bar"]["children"].append(folder) |
| 84 | + |
| 85 | + output = { |
| 86 | + "checksum": "", # Edge should re-calc |
| 87 | + "roots": new_roots, |
| 88 | + "version": 1 |
| 89 | + } |
| 90 | + |
| 91 | + with open("/home/hyper/.var/app/com.microsoft.EdgeDev/config/microsoft-edge-dev/Default/Bookmarks", "w") as f: |
| 92 | + json.dump(output, f, indent=3) |
| 93 | + |
| 94 | + print("Success: Edge Bookmarks file overwritten.") |
| 95 | +except Exception as e: |
| 96 | + print(f"Error: {e}") |
0 commit comments