我正在使用 pycURL 库在 Python 2.7 中编写一个简单的程序,以将文件内容提交到 pastebin。这是程序的代码:
#!/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()
输出的 pastebin 看起来像标准的 Python 列表:['string\n', 'line of text\n', ...]
等等。
有什么办法可以格式化它,让它看起来更好,而且它实际上是人类可读的?另外,如果有人能告诉我如何在POSTFIELDS
. Pastebin APIpaste_code
用作其主要数据输入,但它可以使用可选的东西paste_name
,例如设置上传的名称或paste_private
将其设置为私有。