开发者

Paste to codepad.org using bash or curl

开发者 https://www.devze.com 2022-12-19 15:56 出处:网络
How can I paste to codepad.org from the commandline using c开发者_StackOverflowurl?here\'s a Python script

How can I paste to codepad.org from the commandline using c开发者_StackOverflowurl?


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


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 code@myfile.py codepad.org

(Edited to make it work.)


You can also use reval:

reval test.py
reval -l ruby -e 'p 2+2'
reval prog.hs -p # make private
0

精彩评论

暂无评论...
验证码 换一张
取 消