-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9776667
Showing
8 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pyperclip==1.8.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
deactivate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
source unminipy-env/bin/activate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
python3 -m venv unminipy-env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |