ファイルの内容をpastebinに送信するために、pycURLライブラリを使用してPython 2.7で簡単なプログラムを作成しています。プログラムのコードは次のとおりです。
#!/usr/bin/env python2
import pycurl, os
def send(file):
print "Sending file to pastebin...."
curl = pycurl.Curl()
curl.setopt(pycurl.URL, "http://pastebin.com/api_public.php")
curl.setopt(pycurl.POST, True)
curl.setopt(pycurl.POSTFIELDS, "paste_code=%s" % file)
curl.setopt(pycurl.NOPROGRESS, True)
curl.perform()
def main():
content = raw_input("Provide the FULL path to the file: ")
open = file(content, 'r')
send(open.readlines())
return 0
main()
出力されたペーストビンは、標準の Python リストのように見えます:['string\n', 'line of text\n', ...]
など。
見栄えが良く、実際に人間が読めるようにフォーマットする方法はありますか? また、 で複数のデータ入力を使用する方法を誰か教えていただければ、とてもうれしいですPOSTFIELDS
。Pastebin API は主なデータ入力として を使用しますが、アップロードの名前を設定したり、非公開に設定したりpaste_code
するオプションのものを使用できます。paste_name
paste_private