Skip to content

Instantly share code, notes, and snippets.

@gialloporpora
Created April 27, 2014 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gialloporpora/11340885 to your computer and use it in GitHub Desktop.
Save gialloporpora/11340885 to your computer and use it in GitHub Desktop.
Extracts links from a json file
import re
def elff(filename):
f = open(filename, "r")
s=f.read()
f.close()
regex = re.compile(r'"(http[^"]*)"')
links = regex.findall(s)
return links
def savefile(filename, s):
f = open(filename, "w")
f.write(s)
f.close()
if __name__=='__main__':
import sys
filename = sys.argv[1]
if len(sys.argv)==2: ofilename="%s.html" %filename
else: ofilename=sys.argv[2]
print ofilename
links = elff(filename)
s = "<ol>"
for i in links:
s+= '<li><a href="%s" target="_blank">%s</a></li>\n' %(i, i)
s+="</ol>"
savefile(ofilename, s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment