views:

259

answers:

2

How can I paste to codepad.org from the commandline using curl?

+1  A: 

Yes, you can do it with curl. Assuming your code is Python and in myfile.python, you can do it like this:

$ curl -d "lang=Python&submit=Submit" --data-urlencode [email protected] codepad.org

(Edited to make it work.)

Hans W
This only posts '@myfile.c' on a new paste. I need a way to upload a whole file
M0E-lnx
I'm actually pasting python code, but I do have the file named after the @ in the same directory I'm executing the command from.$ curl -d lang=Python -d [email protected] -d private=False -d submit=Submit codepad.org Still only posts the filename
M0E-lnx
Sorry, you were right, it didn't work. I have edited my reply and it now works for me. Please let me know if it works for you too.
Hans W
The curl method is still not working for me.It says --data-urlencode option is unknown
M0E-lnx
That option was introduced in curl 7.18.0 (jan 2008), so it's quite recent.
Hans W
Oh.. that must be it... I'm using an older version of curl... 2.16.x
M0E-lnx
+3  A: 

here's a Python script

import urllib
import urllib2
url = 'http://codepad.org'
content=open("myscript.py").read()
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("</a>"):
    if "Link:" in href:
        ind=href.index('Link:')
        found = href[ind+5:]
        for i in found.split('">'):
            if '<a href=' in i:
                 print "The link: " ,i.replace('<a href="',"").strip()

output

$ python python.py
The link:  http://codepad.org/W0G8HIzM
ghostdog74
Works like a charm... Thanks a lot man
M0E-lnx