my version of @dis.sociat.ing's dollcode algorithm in python
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

convert any text -> dollcode!

- switched from int-only to string-based input
- removed relevant validation, no longer necessary
- added base256 encoding (encode_256), input now passes thru this first
- renamed various functions (print_dollcode -> print_dcode, convert_number ->
encode_dcode)
- edited pyproject.toml to reflect new changes & bumped semver accordingly

digi 379ad5f3 d9d0a922

+19 -18
+16 -15
main.py
··· 2 2 3 3 import pyperclip 4 4 5 - 6 - def positive_int(val: str): 7 - ival = int(val) 8 - if ival <= 0: 9 - raise argparse.ArgumentTypeError("Number must be positive") 10 - return ival 11 - 12 - 13 - parser = argparse.ArgumentParser(description="converts base-10 number into dollcode") 14 - parser.add_argument("number", type=positive_int, help="positive number to convert") 5 + parser = argparse.ArgumentParser(description="converts input into dollcode") 6 + parser.add_argument("input", type=str, help="input to convert") 15 7 parser.add_argument("-c", action="store_true", help="copy output to clipboard") 16 8 args = parser.parse_args() 17 9 ··· 19 11 BASE_NUM = 3 20 12 21 13 22 - def convert_number(num: int): 14 + def encode_256(input: str): 15 + result = 0 16 + 17 + for char in input: 18 + result = (result * 256) + ord(char) 19 + 20 + return result 21 + 22 + 23 + def encode_dcode(num: int): 23 24 output: list[str] = [] 24 25 window: int = num 25 26 ··· 36 37 return output 37 38 38 39 39 - def print_dollcode(output: list[str], copy: bool): 40 + def print_dcode(output: list[str], copy: bool): 40 41 string: str = "" 41 42 42 43 for char in output: ··· 49 50 print(string) 50 51 51 52 52 - def main(number: int, copy: bool): 53 - print_dollcode(convert_number(number), copy) 53 + def main(input: str, copy: bool): 54 + print_dcode(encode_dcode(encode_256(input)), copy) 54 55 55 56 56 57 if __name__ == "__main__": 57 - main(args.number, args.c) 58 + main(args.input, args.c)
+2 -2
pyproject.toml
··· 1 1 [project] 2 2 name = "dollcode" 3 - version = "0.2.0" 4 - description = "converts base-10 number into dollcode" 3 + version = "0.3.0" 4 + description = "converts input into dollcode" 5 5 readme = "README.md" 6 6 requires-python = ">=3.13" 7 7 dependencies = [
+1 -1
uv.lock
··· 4 4 5 5 [[package]] 6 6 name = "dollcode" 7 - version = "0.2.0" 7 + version = "0.3.0" 8 8 source = { virtual = "." } 9 9 dependencies = [ 10 10 { name = "pyperclip" },