Convert ids to base 62 (shorter url)

This commit is contained in:
Gnarwhal 2024-08-01 17:56:06 +00:00
parent ad63a98bdf
commit 97ea9d1028
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174

View file

@ -71,6 +71,23 @@ class Config:
with open(config_path, mode="rb") as file:
return tomllib.load(file)
def rebase(number):
if number == 0:
return "0"
rebased = ""
while number != 0:
digit = number % 62
if digit < 10:
rebased = chr(digit + 48) + rebased
elif digit < 36:
rebased = chr(digit + 87) + rebased
else:
rebased = chr(digit + 29) + rebased
number = int(number / 62)
return rebased
def main():
arguments = parse_arguments()
@ -101,7 +118,7 @@ def main():
print("Error: must specify one of -f FILE, -l, -p")
sys.exit(1)
target_id = time.time_ns()
target_id = rebase(time.time_ns())
target_file_name = f"{target_id}{target_file_extension}"
target_file = f"{config.ssh_path}/{target_file_name}"
target_destination = f"{config.ssh_user}@{config.host_name}"