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
2010-02-10 19:51:07
This only posts '@myfile.c' on a new paste. I need a way to upload a whole file
M0E-lnx
2010-02-10 20:09:50
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
2010-02-10 20:19:00
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
2010-02-10 21:31:09
The curl method is still not working for me.It says --data-urlencode option is unknown
M0E-lnx
2010-02-10 21:38:03
That option was introduced in curl 7.18.0 (jan 2008), so it's quite recent.
Hans W
2010-02-10 21:43:10
Oh.. that must be it... I'm using an older version of curl... 2.16.x
M0E-lnx
2010-02-10 22:08:09
+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
2010-02-10 20:42:04