Skip to content

Instantly share code, notes, and snippets.

@alice1017
Created January 12, 2011 14:07
Show Gist options
  • Select an option

  • Save alice1017/776194 to your computer and use it in GitHub Desktop.

Select an option

Save alice1017/776194 to your computer and use it in GitHub Desktop.
get code of gist.
#!/usr/bin/python
#coding:utf-8
import sys
import usable # <- it's my module. Please look gist:770826
import urllib
from BeautifulSoup import BeautifulSoup
try:
url = sys.argv[1]
except:
print "ArgumentError"
sys.exit(1)
print "Downloading..."
source = urllib.urlopen(url).read()
soup = BeautifulSoup(source)
code = []
for i in soup.findAll("a"):
if i.string == "raw":
code.append("https://gist.github.com%s" % i.attrs[0][1])
else:
pass
if len(code) == 1:
codeurl = code[0]
file = "./files/%s"% usable.urlanalyze(codeurl)["filename"]
code = urllib.urlopen(codeurl).read()
f = usable.File(file)
TF = f.makefile()
f.changefile(file)
f.writeonly(code)
print "Completed."
else:
for i in code:
file = "./files/%s"% usable.urlanalyze(i)["filename"]
code = urllib.urlopen(i).read()
f = usable.File(file)
TF = f.makefile()
f.changefile(file)
f.writeonly(code)
print "Completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment