Skip to content

Commit

Permalink
unmini.py is alive
Browse files Browse the repository at this point in the history
  • Loading branch information
steebe committed Dec 1, 2023
0 parents commit 9776667
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# VENV/Python
unminipy-env/
__pycache__/
*.pyc
*.spec

# pyinstaller
build/
dist/

# OS
*.local
*.DS_Store
Thumbs.db
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# unminipy

A small utility for unminifying minified JSON to assist with readability.

## script/

To initialize the venv:
```shell
[unminipy]$ script/init.sh
```

To activate the venv:
```shell
[unminipy]$ source script/env-up.sh
```

To deactivate the venv:
```shell
(unminipy-env)[unminipy]$ deactivate

# OR

(unminipy-env)[unminipy]$ source script/env-down.sh
```


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyperclip==1.8.2
2 changes: 2 additions & 0 deletions script/env-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
deactivate
2 changes: 2 additions & 0 deletions script/env-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
source unminipy-env/bin/activate
2 changes: 2 additions & 0 deletions script/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
python3 -m venv unminipy-env
8 changes: 8 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## ci/cd
- workflow for building & publishing
- pip install
- pyinstaller
- publish version to Github under repo releases

## bin
- make a `--save` arg that will save the unminified output to a file
68 changes: 68 additions & 0 deletions unmini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import argparse
import json
import pyperclip

def main():
cli_args = parse_args()
try:
unminified = None

if cli_args.clip:
try:
unminified = json.loads(pyperclip.paste())
except:
print("No valid JSON found in clipboard")
return
elif cli_args.file:
try:
json_file = open(cli_args.file)
unminified = json.loads(json_file.read())
except:
print("File provided is not a valid JSON file")
return

unminifiedPayload = json.dumps(unminified, indent = 2)

if not cli_args.no_copy:
pyperclip.copy(unminifiedPayload)
if cli_args.verbose:
print(unminifiedPayload)
except:
print("The string provided is not valid JSON.")

# Bootstraps the argparse library for providing readable docs & CLI argument handling
def parse_args():
parser = argparse.ArgumentParser(
prog="unminipy",
description="""
Unminify your JSON data for visibility. Provide valid JSON via your clipboard
or a local file, and its unminified form will be provided in your clipboard.
"""
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="print the unminified JSON after unminifying",
required=False
)
parser.add_argument(
"-n",
"--no-copy",
action="store_true",
help="do not update the clipboard with the unminified JSON",
required=False
)
standalone_args = parser.add_mutually_exclusive_group(required=True)
standalone_args.add_argument(
"--clip",
action="store_true",
help="use the data stored in the clipboard as the input"
)
standalone_args.add_argument(
"--file",
help="provide the JSON via a file"
)
return parser.parse_args()

main()

0 comments on commit 9776667

Please sign in to comment.