pasteconnect
0.6.2
CasteConnect是用于与Pastebin互动的Python库。它允许您检查帐户有效性,身份验证,创建糊状,删除糊状并检索RAW PADTE含量。
需要Python 3.7或更高。
您可以使用pip安装过去的连接:
+ $ pip install pasteconnect从源存储库安装
+ $ pip install git+https://github.com/heartlog/pasteconnect.git要使用casteconnect,您需要粘贴凭证,其中包括您的username , password和api_key 。如果您没有这些,则可以通过注册Pastebin帐户并从Pastebin API文档中生成api_key来获取它们。
from pasteconnect import PasteConn
# Initialize a PasteConnect client
pastebin = PasteConn ( username , password , api_key )
# Check account validity
account_status = pastebin . check_account ()
print ( account_status )
title = "My Paste Title"
content = "This is the content of my paste."
# Create a paste on Pastebin
paste_url = pastebin . create_paste ( title , content , privacy = 1 )
print ( f"Paste created: { paste_url } " )要与casteconnect互动,您需要用凭据初始化客户端:
pastebin = PasteConn(username, password, api_key) - required for other methods to work参考入门
username = "your_username"
password = "your_password"
api_key = "your_api_key"
# Initialize the client
pastebin = PasteConn ( username , password , api_key )另外,您可以使用预定义的环境变量初始化
pastebin = PasteConn () # with pre define env var 您可以使用以下方法检查Pastebin帐户的有效性:
pastebin.check_account() result = pastebin . check_account ()
print ( result ) # Response: '[heartlog] is Valid Account. User key : "user_key"' 要身份验证并获取您的user_key ,请使用auth()方法:
pastebin.auth()使用凭据获取user_key 。
result = pastebin . auth ()
print ( result ) # Response: "user_key" 您可以在Pastebin上创建具有标题,内容和隐私级别的糊状物。隐私级别可以是0(公共),1(未列出)或2(私有):
pastebin.create_paste(title, content, privacy=1) privacy = 1 # (default - private)
title = "Title of paste"
content = """
Hello
This is multiline text
"""
pastebin . create_paste ( title , content , privacy = 1 )要删除糊状物,请使用delete_paste(url)方法提供其URL或ID:
pastebin.delete_paste(url) url = "https://pastebin.com/kZATAWhe"
result = pastebin . delete_paste ( url )
print ( result ) # Response: "Paste Removed" 您可以使用其URL或ID检索糊剂的原始内容:
pastebin.get_raw_content(url) from pasteconnect import get_raw
result = get_raw ( url )
print ( result )另外,您可以使用get_raw函数:
url = "https://pastebin.com/your_paste_id"
result = pastebin . get_raw_content ( url )
print ( result ) # Response: "Content of paste"Venaxyt for Pastebinapi。在项目中有很大帮助。 ?