Convert ids to base 62 (shorter url)
This commit is contained in:
parent
ad63a98bdf
commit
97ea9d1028
1 changed files with 18 additions and 1 deletions
|
@ -71,6 +71,23 @@ class Config:
|
||||||
with open(config_path, mode="rb") as file:
|
with open(config_path, mode="rb") as file:
|
||||||
return tomllib.load(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():
|
def main():
|
||||||
arguments = parse_arguments()
|
arguments = parse_arguments()
|
||||||
|
|
||||||
|
@ -101,7 +118,7 @@ def main():
|
||||||
print("Error: must specify one of -f FILE, -l, -p")
|
print("Error: must specify one of -f FILE, -l, -p")
|
||||||
sys.exit(1)
|
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_name = f"{target_id}{target_file_extension}"
|
||||||
target_file = f"{config.ssh_path}/{target_file_name}"
|
target_file = f"{config.ssh_path}/{target_file_name}"
|
||||||
target_destination = f"{config.ssh_user}@{config.host_name}"
|
target_destination = f"{config.ssh_user}@{config.host_name}"
|
||||||
|
|
Loading…
Reference in a new issue