File: countries-get-flag.py

package info (click to toggle)
onionshare 2.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,628 kB
  • sloc: python: 14,487; javascript: 10,725; sh: 137; makefile: 56; xml: 29
file content (55 lines) | stat: -rw-r--r-- 1,443 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
import subprocess
import tempfile
import json
import os


def main():
    tmp_dir = tempfile.TemporaryDirectory()
    flagsdir = os.path.join(tmp_dir.name, "flagsicon")
    subprocess.run(["git", "clone", "https://github.com/lipis/flag-icons.git", flagsdir])

    with open(
        os.path.join("onionshare", "resources", "countries", "en.json")
    ) as f:
        countries = list(json.loads(f.read()))

    os.makedirs(
        os.path.join(
            "onionshare",
            "resources",
            "images",
            "countries",
        ),
        exist_ok=True,
    )

    for country in countries:
        country = country.lower()
        if os.path.isfile(os.path.join(flagsdir, "flags", "4x3", f"{country}.svg")):
            src_filename = os.path.join(flagsdir, "flags", "4x3", f"{country}.svg")
            dest_filename = os.path.join(
                "onionshare",
                "resources",
                "images",
                "countries",
                f"{country}.png",
            )
            subprocess.run(
                [
                    "convert",
                    src_filename,
                    "-background",
                    "none",
                    "-density",
                    "100",
                    "-resize",
                    "64x",
                    dest_filename,
                ]
            )


if __name__ == "__main__":
    main()