Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sherlock-project
GitHub Repository: sherlock-project/sherlock
Path: blob/master/devel/site-list.py
761 views
1
#!/usr/bin/env python
2
# This module generates the listing of supported sites which can be found in
3
# sites.mdx. It also organizes all the sites in alphanumeric order
4
import json
5
import os
6
7
DATA_REL_URI: str = "sherlock_project/resources/data.json"
8
9
DEFAULT_ENCODING = "utf-8"
10
11
# Read the data.json file
12
with open(DATA_REL_URI, "r", encoding=DEFAULT_ENCODING) as data_file:
13
data: dict = json.load(data_file)
14
15
# Removes schema-specific keywords for proper processing
16
social_networks = data.copy()
17
social_networks.pop('$schema', None)
18
19
# Sort the social networks in alphanumeric order
20
social_networks = sorted(social_networks.items())
21
22
# Make output dir where the site list will be written
23
os.mkdir("output")
24
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
34
for social_network, info in social_networks:
35
url_main = info["urlMain"]
36
is_nsfw = "**(NSFW)**" if info.get("isNSFW") else ""
37
site_file.write(f"1. [{social_network}]({url_main}) {is_nsfw}\n")
38
39
# Overwrite the data.json file with sorted data
40
with open(DATA_REL_URI, "w", encoding=DEFAULT_ENCODING) as data_file:
41
sorted_data = json.dumps(data, indent=2, sort_keys=True)
42
data_file.write(sorted_data)
43
data_file.write("\n") # Keep the newline after writing data
44
45
print("Finished updating supported site listing!")
46
47