Update site-list.py

These changes improve readability and maintain the functionality of the original code.
This commit is contained in:
Pallavi Kathait 2024-09-29 21:31:19 +05:30 committed by GitHub
parent f7075e1b64
commit 193de54b6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 6 deletions

View File

@ -8,11 +8,11 @@ import os
DATA_REL_URI: str = "sherlock_project/resources/data.json"
# Read the data.json file
with open(DATA_REL_URI, "r", encoding="utf-8") as data_file:
with open(DATA_REL_URI, "r") as data_file:
data: dict = json.load(data_file)
# Removes schema-specific keywords for proper processing
social_networks: dict = dict(data)
social_networks: dict = data.copy()
social_networks.pop('$schema', None)
# Sort the social networks in alphanumeric order
@ -21,9 +21,15 @@ social_networks: list = sorted(social_networks.items())
# Make output dir where the site list will be written
os.mkdir("output")
# Write the list of supported sites to sites.md
# Write the list of supported sites to sites.mdx
with open("output/sites.mdx", "w") as site_file:
site_file.write("---\ntitle: 'List of supported sites'\nsidebarTitle: 'Supported sites'\nicon: 'globe'\ndescription: 'Sherlock currently supports **400+** sites'\n---\n\n")
site_file.write("---\n")
site_file.write("title: 'List of supported sites'\n")
site_file.write("sidebarTitle: 'Supported sites'\n")
site_file.write("icon: 'globe'\n")
site_file.write("description: 'Sherlock currently supports **400+** sites'\n")
site_file.write("---\n\n")
for social_network, info in social_networks:
url_main = info["urlMain"]
is_nsfw = "**(NSFW)**" if info.get("isNSFW") else ""
@ -33,7 +39,6 @@ with open("output/sites.mdx", "w") as site_file:
with open(DATA_REL_URI, "w") as data_file:
sorted_data = json.dumps(data, indent=2, sort_keys=True)
data_file.write(sorted_data)
data_file.write("\n")
data_file.write("\n") # Keep the newline after writing data
print("Finished updating supported site listing!")