Skip to content

Commit f96610c

Browse files
feat: Implement site name aliases
1 parent 388a1e0 commit f96610c

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

.actor/dataset_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"fields": [
3030
"username",
3131
"links"
32-
],
32+
]
3333
},
3434
"display": {
3535
"component": "table",

sherlock_project/resources/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,7 @@
21882188
"<div class=\"error-panel\"><span>User ",
21892189
"<title>429 Too Many Requests</title>"
21902190
],
2191+
"aliases": ["X"],
21912192
"errorType": "message",
21922193
"regexCheck": "^[a-zA-Z0-9_]{1,15}$",
21932194
"url": "https://x.com/{}",

sherlock_project/resources/data.schema.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@
5151
]
5252
},
5353
"errorUrl": { "type": "string" },
54-
"response_url": { "type": "string" }
55-
},
54+
"response_url": { "type": "string" },
55+
56+
"aliases": {
57+
"type": "array",
58+
"items": {
59+
"type": "string"
60+
}
61+
},
5662
"dependencies": {
5763
"errorMsg": {
5864
"properties" : { "errorType": { "const": "message" } }

sherlock_project/sherlock.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -829,23 +829,33 @@ def main():
829829
# Eventually, the rest of the code will be updated to use the new object
830830
# directly, but this will glue the two pieces together.
831831
site_data_all = {site.name: site.information for site in sites}
832-
if args.site_list == []:
832+
if not args.site_list:
833833
# Not desired to look at a sub-set of sites
834834
site_data = site_data_all
835835
else:
836836
# User desires to selectively run queries on a sub-set of the site list.
837837
# Make sure that the sites are supported & build up pruned site database.
838838
site_data = {}
839839
site_missing = []
840-
for site in args.site_list:
841-
counter = 0
842-
for existing_site in site_data_all:
843-
if site.lower() == existing_site.lower():
844-
site_data[existing_site] = site_data_all[existing_site]
845-
counter += 1
846-
if counter == 0:
847-
# Build up list of sites not supported for future error message.
848-
site_missing.append(f"'{site}'")
840+
841+
# Create a mapping from all site names and aliases (in lowercase) to their proper names
842+
site_map = {}
843+
for site_name, site_info in site_data_all.items():
844+
site_map[site_name.lower()] = site_name
845+
if "aliases" in site_info:
846+
for alias in site_info["aliases"]:
847+
site_map[alias.lower()] = site_name
848+
849+
for site_name_from_user in args.site_list:
850+
# Find the proper site name from the user's input (which could be an alias)
851+
proper_site_name = site_map.get(site_name_from_user.lower())
852+
853+
if proper_site_name:
854+
# If a match was found, add the site's data to our list
855+
site_data[proper_site_name] = site_data_all[proper_site_name]
856+
else:
857+
# If no match was found for the name or any alias
858+
site_missing.append(f"'{site_name_from_user}'")
849859

850860
if site_missing:
851861
print(f"Error: Desired sites not found: {', '.join(site_missing)}.")

0 commit comments

Comments
 (0)