update to modified_users.py fixes load times and other issues. Thanks to xwindows.

This commit is contained in:
2022-12-31 20:00:02 +00:00
parent ca38d62131
commit 05c820f908
4 changed files with 134 additions and 13 deletions

55
modified_users.old.py Executable file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env python
import hashlib
import json
import os
LINK = "1~{0} /~{0} tilde.club 70"
def compare_gophermaps(user, cache):
user_path = f"/home/{user}/public_gopher/gophermap"
if not os.path.exists(user_path):
# Ignore user if public_gopher folder is not found
return
if user in cache:
print(LINK.format(user))
return
skel_path = "/etc/skel/public_gopher/gophermap"
skel_hash = hashlib.sha256()
with open(skel_path, "rb") as f:
skel_hash.update(f.read())
try:
user_hash = hashlib.sha256()
with open(user_path, "rb") as f:
user_hash.update(f.read())
if user_hash.hexdigest() != skel_hash.hexdigest():
cache[user]=True
print(LINK.format(user))
except PermissionError:
# Ignore PermissionError exceptions and treat the gophermap file as one to not list
pass
def main():
cache_path = "cache.json"
# Load the cache from disk if it exists, otherwise create a new cache
if os.path.exists(cache_path):
with open(cache_path, "r") as f:
cache = json.load(f)
else:
cache = {}
for user in sorted(os.listdir("/home"), key=lambda x: x.lower()):
compare_gophermaps(user, cache)
# Save the cache to disk
with open(cache_path, "w") as f:
json.dump(cache, f)
if __name__ == "__main__":
main()