snipplr :: getCode()


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # Snippler - getCode()
  2. # snipplr
  3. # Author : Abhinay Omkar
  4.  
  5. import re,urllib2,sys
  6.  
  7. # input url = "http://snipplr.com/view/8/ajax-edit-in-place/"
  8. try:
  9. inurl = sys.argv[1]
  10. except:
  11. print "Err: url is missing."
  12. sys.exit()
  13. try:
  14. path = sys.argv[2]
  15. except:
  16. path = inurl.split('/')[-2]
  17.  
  18. num = re.sub(r'[a-zA-Z/:\-.]*','',inurl)
  19.  
  20. url = "http://snipplr.com/view.php?codeview&id="+num
  21.  
  22. raw = repr(urllib2.urlopen(url).read())
  23. prog = re.compile(r'<textarea rows="25">(.*)</textarea>').search(raw).group()
  24. open
  25.  
  26. prog = prog.replace('\\r\\n','\n').replace('\\t',' ')[20:-11]
  27. print "File "+path+" Opened..."
  28. print prog
  29. open(path,'w').write(prog)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.