diff options
| author | ache <ache@ache.one> | 2026-01-06 23:49:59 +0100 |
|---|---|---|
| committer | ache <ache@ache.one> | 2026-01-06 23:49:59 +0100 |
| commit | 6aed512bef118d6c415f509dc44b7d2895f89bfb (patch) | |
| tree | c9750bbce7941e7bc2a8e4f9d9644f8eb3785c88 | |
| parent | docs: update README.md to highlight tool's functionality and list similar pro... (diff) | |
feat: Rename username to address
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | src/lolbin/cli.py | 105 |
2 files changed, 59 insertions, 56 deletions
@@ -6,7 +6,7 @@ It does only that but it does it well. **WARNING**: Remember that every past on paste.lol is **public**. If you have the URL of the paste, you can fetch it without authentication. -You can access every listed paste of someone on the web at "https://paste.lol/<username>". +You can access every listed paste of someone on the web at "https://paste.lol/<address>". Mines are here: <https://paste.lol/ache>. @@ -17,7 +17,7 @@ Mines are here: <https://paste.lol/ache>. - **Show Paste** - Displays the content of a specific paste by its title. - **Delete Paste** - Deletes a specific paste by its title. - **Help Message** - Provides usage instructions for the tool. -- **Debug Mode** - Prints the action to be performed, the paste name, username, and bearer token (but does not actually perform the action). +- **Debug Mode** - Prints the action to be performed, the paste name, address, and bearer token (but does not actually perform the action). <!-- TODO: Make a manuel page! (`man lolbin`) @@ -64,7 +64,7 @@ $ yay -S lolbin To configure the tool, create a file `~/.config/lolbin/config.toml` with the following content: ```toml -username = "your_username" +address = "your_address" bearer_token = "your_bearer_token" ``` @@ -75,14 +75,14 @@ If you don't want to store you API token inside a config file, you can call exte With the backtick syntax for command substitution: ```toml -username = "your_username" +address = "your_address" bearer_token = "`bws secret get XXXXXX` | jq .key --raw-output" ``` Or with the dollard based one: ```toml -username = "your_username" +address = "your_address" bearer_token = "$ pass api.omg.lol/token_lolbin" ``` diff --git a/src/lolbin/cli.py b/src/lolbin/cli.py index 64b8457..265a188 100644 --- a/src/lolbin/cli.py +++ b/src/lolbin/cli.py @@ -16,7 +16,7 @@ CONFIG_FILENAME = "config.toml" DEFAULT_DOMAIN = "api.omg.lol" USAGE_STRING = """ usage: lolbin [-h] [--delete PASTE_NAME] [-e PASTE_NAME] [--paste PASTE_NAME] [--file FILE] [--list] - [--public] [--user USERNAME] [--show PASTE_NAME] [--debug] [--help] [-L] [-P] [-u] + [--public] [--address address] [--show PASTE_NAME] [--debug] [--help] [-L] [-P] [-u] A command-line interface tool for managing pastes on paste.lol. @@ -27,12 +27,12 @@ optional arguments: --paste PASTE_NAME Create or update a paste with specified title and content from standard input. --file FILE Specify a file to read the content for creating/updating a paste instead of standard input. --list Lists all your pastes along with their titles and modification time (default action). - --user USERNAME, -u USERNAME - THe username to request the past from + --address ADDRESS, -u ADDRESS + The address to request the past from --show PASTE_NAME Displays the content of a specific paste by its title. --delete PASTE_NAME, -d PASTE_NAME Deletes a specific paste by its title. - --debug Print actions, paste name, username, and bearer token without performing any action. + --debug Print actions, paste name, address, and bearer token without performing any action. --listed, -L List only public (listed) pastes. Opposite of private (non-listed). --public, -P Alias for --listed. @@ -89,14 +89,14 @@ def get_config(): return tomli.load(f) -def create_paste(paste, content, username, token, public): +def create_paste(paste, content, address, token, public): """ Create a paste on omg.lol. Args: paste (str): The paste name (id). An string of characters (ASCII only without spaces). content (str): The content of the paste. - username (str): The username of the user. + address (str): The address of the user. token (str): The authentification token. You can get it from <https://home.omg.lol/account> public (bool): True to make the paste listed. """ @@ -105,7 +105,7 @@ def create_paste(paste, content, username, token, public): if public: data_send["listed"] = "true" # NOTE: It's a not documented feature response = requests.post( - f"https://{DEFAULT_DOMAIN}/address/{username}/pastebin/", + f"https://{DEFAULT_DOMAIN}/address/{address}/pastebin/", headers=headers, data=json.dumps(data_send), ) @@ -127,7 +127,7 @@ def create_paste(paste, content, username, token, public): message = data["response"]["message"] print(message[: message.index(".") + 1]) print( - f"This paste is {f'listed on https://paste.lol/{username}' if public else 'non-listed'}" + f"This paste is {f'listed on https://paste.lol/{address}' if public else 'non-listed'}" ) message = message[message.index(".") + 1 :] message = message[message.index('"') + 1 :] @@ -139,12 +139,12 @@ def create_paste(paste, content, username, token, public): print("No reponse returned") -def list_paste(username, token, public): +def list_paste(address, token, public): """ List all pastes for a user. Args: - username (str): The username of the user. + address (str): The address of the user. token (str): The authentification token. You can get it from <https://home.omg.lol/account> public (bool): Whether to list public pastes or not. """ @@ -155,7 +155,7 @@ def list_paste(username, token, public): else {"Authorization": f"Bearer {get_token(token)}"} ) response = requests.get( - f"https://{DEFAULT_DOMAIN}/address/{username}/pastebin", headers=headers + f"https://{DEFAULT_DOMAIN}/address/{address}/pastebin", headers=headers ) data = response.json() @@ -184,7 +184,7 @@ def list_paste(username, token, public): print(f" - {paste['title']} ({modified_on_string})") -def get_paste(paste, username, token): +def get_paste(paste, address, token): """ Get a paste. @@ -194,7 +194,7 @@ def get_paste(paste, username, token): """ headers = {} if token is None else {"Authorization": f"Bearer {get_token(token)}"} response = requests.get( - f"https://{DEFAULT_DOMAIN}/address/{username}/pastebin/{paste}", headers=headers + f"https://{DEFAULT_DOMAIN}/address/{address}/pastebin/{paste}", headers=headers ) data = response.json() @@ -214,19 +214,19 @@ def get_paste(paste, username, token): return None, None -def show_paste(paste, username, token): +def show_paste(paste, address, token): """ Show a paste. Args: paste (str): The paste name (id). An string of characters (ASCII only without spaces). - username (str): The username of the user. + address (str): The address of the user. token (str): The authentification token. You can get it from <https://home.omg.lol/account> """ headers = {} if token is None else {"Authorization": f"Bearer {get_token(token)}"} response = requests.get( - f"https://{DEFAULT_DOMAIN}/address/{username}/pastebin/{paste}", headers=headers + f"https://{DEFAULT_DOMAIN}/address/{address}/pastebin/{paste}", headers=headers ) data = response.json() @@ -252,18 +252,18 @@ def show_paste(paste, username, token): print("No content found for the paste.") -def delete_paste(paste, username, token): +def delete_paste(paste, address, token): """ Delete a paste. Args: paste (str): The paste name (id). An string of characters (ASCII only without spaces). - username (str): The username of the user. + address (str): The address of the user. token (str): The authentification token. You can get it from <https://home.omg.lol/account> """ headers = {"Authorization": f"Bearer {get_token(token)}"} response = requests.delete( - f"https://{DEFAULT_DOMAIN}/address/{username}/pastebin/{paste}", headers=headers + f"https://{DEFAULT_DOMAIN}/address/{address}/pastebin/{paste}", headers=headers ) data = response.json() @@ -286,7 +286,7 @@ def delete_paste(paste, username, token): print("No reponse found but the paste was succesfully deleted") -def debug_action(action, paste_name, content, username, token, public): +def debug_action(action, paste_name, content, address, token, public): """ Print debug information about the action being performed. @@ -294,13 +294,13 @@ def debug_action(action, paste_name, content, username, token, public): action (str): The action being performed. paste_name (str): The name of the paste. content (str): The content of the paste. - username (str): The username of the user. + address (str): The address of the user. token (str): The authentification token. You can get it from <https://home.omg.lol/account> public (bool): Whether the paste is public or not. """ print(f"Debug: Action = {action}") print(f"Paste Name: {paste_name}") - print(f"Username: {username}") + print(f"Address: {address}") print(f"Bearer Token: {token}") print(f"Public: {public}") if content is not None: @@ -309,13 +309,13 @@ def debug_action(action, paste_name, content, username, token, public): ) # Print first 100 characters of the content -def edit_paste(paste, username, token): +def edit_paste(paste, address, token): """ Edit a paste: It opens it in your default editor, then updates it on paste.lol. Args: paste (str): The paste name (id). An string of characters (ASCII only without spaces). - username (str): The username of the user. + address (str): The address of the user. token (str): The authentification token. You can get it from <https://home.omg.lol/account> """ @@ -323,7 +323,7 @@ def edit_paste(paste, username, token): token = get_token(token) editor = os.environ.get("EDITOR", "vim") # that easy! - content, is_listed = get_paste(paste, username, token) + content, is_listed = get_paste(paste, address, token) if content is None: print(f"Unable to retrieve the paste {paste}.") @@ -353,7 +353,7 @@ def edit_paste(paste, username, token): create_paste( paste=paste, content=new_content, - username=username, + address=address, token=token, public=is_listed, ) @@ -368,7 +368,7 @@ def app(): paste_name = None content = None is_debug = False - replace_username = False + replace_address = False is_public = False config = get_config() @@ -419,17 +419,20 @@ def app(): action = "show" case "--user" | "-u": - if not replace_username: - replace_username = True - if "username" in config: + if not replace_address: + replace_address = True + if "address" in config: # NOTE: Otherwise the token can't be correct config["bearer_token"] = None - config["username"] = sys.argv[i + 2] + config["address"] = sys.argv[i + 2] to_pass = 1 else: - print("Ambiguous username", file=sys.stderr) + print( + "Address address: Address specified multiple times.", + file=sys.stderr, + ) sys.exit(1) case "--delete" | "-d": @@ -484,7 +487,7 @@ def app(): action, paste_name, content, - config["username"], + config["address"], config["bearer_token"], is_public, ) @@ -492,21 +495,21 @@ def app(): match action: case "list": - if "username" not in config: - print("Error: No username provided.", file=sys.stderr) + if "address" not in config: + print("Error: No address provided.", file=sys.stderr) sys.exit(1) list_paste( - config["username"], + config["address"], config["bearer_token"] if "bearer_token" in config else None, is_public, ) case "paste": - if "username" not in config: - print("Error: No username provided.", file=sys.stderr) + if "address" not in config: + print("Error: No address provided.", file=sys.stderr) sys.exit(1) if "bearer_token" not in config: print( - f"Error: No token provided for the user {config['username']}.", + f"Error: No token provided for the user {config['address']}.", file=sys.stderr, ) sys.exit(1) @@ -518,7 +521,7 @@ def app(): create_paste( paste_name, content, - config["username"], + config["address"], config["bearer_token"], is_public, ) @@ -526,40 +529,40 @@ def app(): if paste_name is None: print("You must specify a paste name to delete.", file=sys.stderr) sys.exit(1) - if "username" not in config: - print("Error: No username provided.", file=sys.stderr) + if "address" not in config: + print("Error: No address provided.", file=sys.stderr) sys.exit(1) if "bearer_token" not in config: print( - f"Error: No token provided for the user {config['username']}.", + f"Error: No token provided for the user {config['address']}.", file=sys.stderr, ) sys.exit(1) - delete_paste(paste_name, config["username"], config["bearer_token"]) + delete_paste(paste_name, config["address"], config["bearer_token"]) case "show": if paste_name is None: print("You must specify a paste name to show.", file=sys.stderr) sys.exit(1) - if "username" not in config: - print("Error: No username provided.", file=sys.stderr) + if "address" not in config: + print("Error: No address provided.", file=sys.stderr) sys.exit(1) show_paste( paste_name, - config["username"], + config["address"], config["bearer_token"] if "bearer_token" in config else None, ) case "help": help_message() case "edit": - if "username" not in config: - print("Error: No username provided.", file=sys.stderr) + if "address" not in config: + print("Error: No address provided.", file=sys.stderr) sys.exit(1) if "bearer_token" not in config: print( - f"Error: No token provided for the user {config['username']}.", + f"Error: No token provided for the user {config['address']}.", file=sys.stderr, ) sys.exit(1) @@ -567,7 +570,7 @@ def app(): if paste_name is None: print("You must specify a paste name to edit.", file=sys.stderr) sys.exit(1) - edit_paste(paste_name, config["username"], config["bearer_token"]) + edit_paste(paste_name, config["address"], config["bearer_token"]) case _: print(f"Unknown action: {action}", file=sys.stderr) sys.exit(1) |