segunda-feira, 14 de junho de 2010

codepad - facilitando a postagem de códigos.

código em python destinado a facilidade em postar códigos no codepad.
o uso é bem simples, basta copiar algo e em seguida vc executa o código
então ele vai te retornar o link da postagem na área de transferência, é tão simples quanto copiar e colar.

#!/usr/bin/python
import pygtk
#pygtk.require('2.0')
import gtk
import urllib
import urllib2

clipboard = gtk.Clipboard()
content = clipboard.wait_for_text()

url = 'http://codepad.org'
values = {'lang' : 'Python',
          'code' : content,
          'submit':'Submit'}

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()

for href in the_page.split(""):
    if "Link:" in href:
        ind=href.index('Link:')
        found = href[ind+5:]
        for i in found.split('">'): 
            if '<a href=' in i:
            link =  i.replace('<a href="',"").strip()
clipboard = gtk.clipboard_get()
text = clipboard.wait_for_text()
text = clipboard.set_text(link)
clipboard.store()
try:
    import pynotify
    if pynotify.init("My Application Name"):
        n = pynotify.Notification("Codepad content",content)
        n.show()
    else:
        print "there was a problem initializing the pynotify module"
except:
        print "you don't seem to have pynotify installed"


Nenhum comentário:

Postar um comentário