Created
August 2, 2013 18:09
-
-
Save sarathsp06/6142041 to your computer and use it in GitHub Desktop.
Js File formatter
This file contains hidden or 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
#!/usr/bin/python | |
import urllib2, re,sys | |
a='' | |
if len(sys.argv) == 2: | |
a=sys.argv[1] | |
else: | |
a=raw_input("Enter the url :") | |
req = urllib2.Request(a) | |
resp = urllib2.urlopen(req) | |
html = resp.read() | |
def indent(a): | |
a=a.group(0) | |
if a=='{': | |
return "\n"+a | |
elif a=='}' or a==';': | |
return a+"\n" | |
html=re.sub("[{};]",indent,html) | |
count=0 | |
Html='' | |
html=html.split('\n') | |
for i in html: | |
try: | |
if i[0] =='{': | |
count+=1 | |
Html+="\n"+' '*count+i | |
if i[-1]=='}': | |
count-=1 | |
except: | |
pass | |
open(a.split('/')[-1],'w+').write(Html) | |
print 'The js file is stored with proper indentation in \' %s \'\nhere are the json links' %a.split('/')[-1] | |
for i in set(re.findall("\"http:[^;\]{}]*\.json\"", ''.join(html))): | |
print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a simple program that can be used to make the js files pritty formatted and will return all json links it has