💾 Archived View for xoc3.io › blog › 2021-08-31 captured on 2023-04-19 at 22:27:30. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-04-28)

-=-=-=-=-=-=-

back to xoc3.io

2021-08-31 - urlencode & urldecode

i've been up to a lot of things recently including:

but unrelated to all of that, this post is about 3 nearly identical python snippets i improved upon from finding on stack overflow:

alias urlencode='python3 -c "import urllib.parse, sys; print(urllib.parse.quote(\" \".join(sys.argv[1:]) if len(sys.argv) > 1 else sys.stdin.read()[0:-1]))"'
alias urlencodeslash='python3 -c "import urllib.parse, sys; print(urllib.parse.quote(  \" \".join(sys.argv[1:]) if len(sys.argv) > 1 else sys.stdin.read()[0:-1], \"\"))"'
alias urldecode='python3 -c "import urllib.parse, sys; print(urllib.parse.unquote(\" \".join(sys.argv[1:]) if len(sys.argv) > 1 else sys.stdin.read()[0:-1]))"'

these aliases do what they say. the first one encodes text to url encoding. the second one encodes, but will also encode slashes too. and the third one decodes url encoding into plain text. all 3 aliases work with either cli args or reading from stdin. i looked this up because i was using a lot of curl for work recently and found myself needing to urlencode/decode things a bunch. it's always nice to add another small tool to your cli belt.

here is that stack overflow post