Skip to content

Instantly share code, notes, and snippets.

@jftuga
Last active December 25, 2018 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jftuga/790cc74428ab9a9d96f7c5fc7e228780 to your computer and use it in GitHub Desktop.
Save jftuga/790cc74428ab9a9d96f7c5fc7e228780 to your computer and use it in GitHub Desktop.
Sort entries in Sherlock data.json file
#!/usr/bin/env python3
# sort entries listed in https://github.com/sdushantha/sherlock/blob/master/data.json
import re
fname = "data.json"
site_re = re.compile('(".*?\},)',re.M|re.S)
name_re = re.compile('"(.*?)": \{')
def main():
all_entries = {}
with open(fname,encoding="latin1") as fp:
data = fp.read()
# add a comma to the last entry, so that the RE will include it
data = re.sub(" \}\n"," },",data)
match = site_re.findall(data)
for entry in match:
match2 = name_re.findall(entry)
site_name = match2[0]
all_entries[site_name] = entry
# case-insensitive sort
sorted_entries = sorted(list(all_entries.keys()), key=str.lower)
print("{")
total = len(sorted_entries)
current = 0
for entry in sorted_entries:
current += 1
if current == total:
# do not include a comma after last entry
print( re.sub(" \},", " }", all_entries[entry]))
else:
print(all_entries[entry])
print("}")
if "__main__" == __name__:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment