Formatting
This commit is contained in:
parent
deb52bf348
commit
27fe210429
1 changed files with 15 additions and 4 deletions
19
main.py
19
main.py
|
@ -29,13 +29,18 @@ try:
|
||||||
raise ImportError("User requested to skip cache")
|
raise ImportError("User requested to skip cache")
|
||||||
print("Trying to load user mappings from cache...")
|
print("Trying to load user mappings from cache...")
|
||||||
from cache import userMappings
|
from cache import userMappings
|
||||||
print("Cache load OK. Reminder: If you need to regenerate the cache, call the script with `--no-cache`")
|
|
||||||
|
print(
|
||||||
|
"Cache load OK. Reminder: If you need to regenerate the cache, call the script with `--no-cache`"
|
||||||
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
users_list = []
|
users_list = []
|
||||||
print("Cache load failed, falling back to full load from slack...")
|
print("Cache load failed, falling back to full load from slack...")
|
||||||
cursor = "N/A"
|
cursor = "N/A"
|
||||||
pages = 0
|
pages = 0
|
||||||
while cursor: # If slack gives us a cursor, then we ain't done loading user data yet
|
while (
|
||||||
|
cursor
|
||||||
|
): # If slack gives us a cursor, then we ain't done loading user data yet
|
||||||
data = ""
|
data = ""
|
||||||
if cursor != "N/A":
|
if cursor != "N/A":
|
||||||
data = client.users_list(cursor=cursor, limit=1000)
|
data = client.users_list(cursor=cursor, limit=1000)
|
||||||
|
@ -47,7 +52,11 @@ except ImportError:
|
||||||
print(f"Pages of users loaded: {pages}")
|
print(f"Pages of users loaded: {pages}")
|
||||||
del pages
|
del pages
|
||||||
print("Building user mappings now, this shouldn't take long...")
|
print("Building user mappings now, this shouldn't take long...")
|
||||||
for user in users_list: # Map user ID mentions to user name mentions, it's nicer when printing messages for thread selection.
|
for (
|
||||||
|
user
|
||||||
|
) in (
|
||||||
|
users_list
|
||||||
|
): # Map user ID mentions to user name mentions, it's nicer when printing messages for thread selection.
|
||||||
userMappings[f"<@{user['id']}>"] = (
|
userMappings[f"<@{user['id']}>"] = (
|
||||||
f"<@{user['profile']['display_name_normalized']}>"
|
f"<@{user['profile']['display_name_normalized']}>"
|
||||||
if user["profile"]["display_name_normalized"]
|
if user["profile"]["display_name_normalized"]
|
||||||
|
@ -58,7 +67,9 @@ except ImportError:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
print("All mappings generated, writing cache file now...")
|
print("All mappings generated, writing cache file now...")
|
||||||
with open("cache.py", "w") as cacheFile: # It is many times faster to load from a local file instead of from slack
|
with open(
|
||||||
|
"cache.py", "w"
|
||||||
|
) as cacheFile: # It is many times faster to load from a local file instead of from slack
|
||||||
cacheFile.write(f"userMappings = {userMappings}")
|
cacheFile.write(f"userMappings = {userMappings}")
|
||||||
print("Cache saved.")
|
print("Cache saved.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue