|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # This module generates the listing of supported sites which can be found in |
3 | | -# sites.md. It also organizes all the sites in alphanumeric order |
| 3 | +# sites.mdx. It also organizes all the sites in alphanumeric order |
4 | 4 | import json |
5 | 5 | import os |
6 | 6 |
|
7 | | - |
8 | 7 | DATA_REL_URI: str = "sherlock_project/resources/data.json" |
9 | 8 |
|
| 9 | +DEFAULT_ENCODING = "utf-8" |
| 10 | + |
10 | 11 | # Read the data.json file |
11 | | -with open(DATA_REL_URI, "r", encoding="utf-8") as data_file: |
| 12 | +with open(DATA_REL_URI, "r", encoding=DEFAULT_ENCODING) as data_file: |
12 | 13 | data: dict = json.load(data_file) |
13 | 14 |
|
14 | 15 | # Removes schema-specific keywords for proper processing |
15 | | -social_networks: dict = dict(data) |
| 16 | +social_networks = data.copy() |
16 | 17 | social_networks.pop('$schema', None) |
17 | 18 |
|
18 | 19 | # Sort the social networks in alphanumeric order |
19 | | -social_networks: list = sorted(social_networks.items()) |
| 20 | +social_networks = sorted(social_networks.items()) |
20 | 21 |
|
21 | 22 | # Make output dir where the site list will be written |
22 | 23 | os.mkdir("output") |
23 | 24 |
|
24 | | -# Write the list of supported sites to sites.md |
25 | | -with open("output/sites.mdx", "w") as site_file: |
26 | | - site_file.write("---\ntitle: 'List of supported sites'\nsidebarTitle: 'Supported sites'\nicon: 'globe'\ndescription: 'Sherlock currently supports **400+** sites'\n---\n\n") |
| 25 | +# Write the list of supported sites to sites.mdx |
| 26 | +with open("output/sites.mdx", "w", encoding=DEFAULT_ENCODING) as site_file: |
| 27 | + site_file.write("---\n") |
| 28 | + site_file.write("title: 'List of supported sites'\n") |
| 29 | + site_file.write("sidebarTitle: 'Supported sites'\n") |
| 30 | + site_file.write("icon: 'globe'\n") |
| 31 | + site_file.write("description: 'Sherlock currently supports **400+** sites'\n") |
| 32 | + site_file.write("---\n\n") |
| 33 | + |
27 | 34 | for social_network, info in social_networks: |
28 | 35 | url_main = info["urlMain"] |
29 | 36 | is_nsfw = "**(NSFW)**" if info.get("isNSFW") else "" |
30 | 37 | site_file.write(f"1. [{social_network}]({url_main}) {is_nsfw}\n") |
31 | 38 |
|
32 | 39 | # Overwrite the data.json file with sorted data |
33 | | -with open(DATA_REL_URI, "w") as data_file: |
| 40 | +with open(DATA_REL_URI, "w", encoding=DEFAULT_ENCODING) as data_file: |
34 | 41 | sorted_data = json.dumps(data, indent=2, sort_keys=True) |
35 | 42 | data_file.write(sorted_data) |
36 | | - data_file.write("\n") |
| 43 | + data_file.write("\n") # Keep the newline after writing data |
37 | 44 |
|
38 | 45 | print("Finished updating supported site listing!") |
39 | | - |
|
0 commit comments