pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

python private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Alcides Fonseca on Tue 17 Jul 21:25
report abuse | download | new post

  1. #!/usr/bin/python2.4
  2.  
  3. def list(xmlcode):
  4.         import urllib2
  5.         import os
  6.         from xml.dom.minidom import parse, parseString
  7.  
  8.         def getContent(tag,parent):
  9.                 if parent.getElementsByTagName(tag)[0].firstChild:
  10.                         return parent.getElementsByTagName(tag)[0].firstChild.nodeValue.encode('ascii', 'xmlcharrefreplace')
  11.                 else:
  12.                         return ""
  13.  
  14.         useragent = os.environ['HTTP_USER_AGENT']
  15.         referer = os.environ['SCRIPT_URI']
  16.        
  17.        
  18.         file = urllib2.urlopen("http://www.text-link-ads.com/xml.php?inventory_key="+xmlcode+"&referer="+referer+"&user_agent="+useragent)
  19.         dom = parse(file)
  20.         links = dom.getElementsByTagName("Links")[0]
  21.  
  22.         list=[]
  23.         for link in links.getElementsByTagName("Link"):
  24.                 url = getContent('URL',link)
  25.                 text = getContent('Text',link)
  26.                 btext = getContent('BeforeText',link)
  27.                 atext = getContent('AfterText',link)
  28.                 list.append(str(btext) + "<a href='" + str(url) + "' target='_blank'>" + str(text) + "</a>" + str(atext))
  29.         return list
  30.  
  31. if __name__ == __main__:
  32.         print "<ul>"
  33.         for link in list("XXXXXXXXXXXXXX"):
  34.                 print "<li>" + link + "</li>"
  35.         print "</ul>"

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me