Skip to content

Instantly share code, notes, and snippets.

@m4ll0k
Last active September 4, 2023 06:45
Show Gist options
  • Save m4ll0k/033c81a36e1e3cf06e8eb9d42e881a1e to your computer and use it in GitHub Desktop.
Save m4ll0k/033c81a36e1e3cf06e8eb9d42e881a1e to your computer and use it in GitHub Desktop.
Javascript Beautifier with Python
# by m4ll0k
# github.com/m4ll0k
import sys
try:
import jsbeautifier
import requests
except Exception as e:
sys.exit(print("{0}.. please download this module/s".format(e)))
def beauty(content:str)->str:
return jsbeautifier.beautify(content.decode())
def getjs(url:str)->dict:
try:
r = requests.get(url)
if r.status_code == 200:
return r
except:
return {"content":"","status_code":500}
def main()->None:
try:
url = sys.argv[1]
output = sys.argv[2]
except:
sys.exit(print("\nUsage:\tpython3 {0} <url> <output>\n".format(sys.argv[0])))
if '.js' in url:
r = getjs(url)
if r.status_code == 200:
js = beauty(r.content)
if output:
_file = open(sys.argv[2],"w")
_file.write(js)
_file.close()
print("Done! file saved here -> \"{0}\"".format(_file.name))
else:
sys.exit(print("\".js\" not found in URL ({}).. check your url".format(sys.argv[1])))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment