about summary refs log tree commit diff stats
path: root/home-manager/firefox/generate-extension.py
blob: cfb735428e9216448938cc528e4e040ac4d2a6dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# source: https://github.com/etu/nixconfig/blob/ba47d577c8bfb4a1c06927c34ece34118f4a0460/modules/graphical/firefox/generate.py

from concurrent.futures import ThreadPoolExecutor
import json
import os
import requests

EXTENSIONS = sorted([
    "darkreader",
    "firenvim",
    "keepassxc-browser",
    "simple-tab-groups",
])

def index_ext(ext: str):
    print(f"Indexing {ext}...")

    resp = requests.get(f"https://addons.mozilla.org/api/v5/addons/addon/{ext}/").json()
    rel = resp["current_version"]

    if not rel["file"]["hash"].startswith("sha256:"):
        raise ValueError("Unhandled hash type")

    return {
        "pname": ext,
        "version": rel["version"],
        "addonId": resp["guid"],
        "url": rel["file"]["url"],
        "sha256": rel["file"]["hash"],
    }

if __name__ == "__main__":
    outfile = os.path.dirname(os.path.realpath(__file__)) + "/extensions.json"

    with ThreadPoolExecutor() as e:
        extensions = {ext: e.submit(index_ext, ext) for ext in EXTENSIONS}
        extensions = {k: v.result() for k, v in extensions.items()}

    with open(outfile, "w") as f:
        json.dump(extensions, f, indent=2)