Skip to content

Commit 9483886

Browse files
Cleanup site-list.py (sherlock-project#2307)
2 parents ef55f7d + 79973a5 commit 9483886

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

devel/site-list.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
#!/usr/bin/env python
22
# 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
44
import json
55
import os
66

7-
87
DATA_REL_URI: str = "sherlock_project/resources/data.json"
98

9+
DEFAULT_ENCODING = "utf-8"
10+
1011
# 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:
1213
data: dict = json.load(data_file)
1314

1415
# Removes schema-specific keywords for proper processing
15-
social_networks: dict = dict(data)
16+
social_networks = data.copy()
1617
social_networks.pop('$schema', None)
1718

1819
# Sort the social networks in alphanumeric order
19-
social_networks: list = sorted(social_networks.items())
20+
social_networks = sorted(social_networks.items())
2021

2122
# Make output dir where the site list will be written
2223
os.mkdir("output")
2324

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+
2734
for social_network, info in social_networks:
2835
url_main = info["urlMain"]
2936
is_nsfw = "**(NSFW)**" if info.get("isNSFW") else ""
3037
site_file.write(f"1. [{social_network}]({url_main}) {is_nsfw}\n")
3138

3239
# 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:
3441
sorted_data = json.dumps(data, indent=2, sort_keys=True)
3542
data_file.write(sorted_data)
36-
data_file.write("\n")
43+
data_file.write("\n") # Keep the newline after writing data
3744

3845
print("Finished updating supported site listing!")
39-

0 commit comments

Comments
 (0)