42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
|
import requests
|
||
|
|
||
|
def paste_to_centos(text, title=None, name=None, private=False, lang=None, expire=None):
|
||
|
"""
|
||
|
Paste text to paste.centos.org and return the URL of the created paste.
|
||
|
|
||
|
:param text: The content to paste (required)
|
||
|
:param title: Title for the paste (optional)
|
||
|
:param name: Author's name (optional)
|
||
|
:param private: Make paste private if True (optional)
|
||
|
:param lang: Language for syntax highlighting (optional)
|
||
|
:param expire: Expiration time in minutes (optional)
|
||
|
:return: URL of the created paste or error message
|
||
|
"""
|
||
|
url = "https://paste.centos.org/api/create"
|
||
|
|
||
|
data = {
|
||
|
"text": text
|
||
|
}
|
||
|
|
||
|
if title:
|
||
|
data["title"] = title
|
||
|
if name:
|
||
|
data["name"] = name
|
||
|
if private:
|
||
|
data["private"] = 1
|
||
|
if lang:
|
||
|
data["lang"] = lang
|
||
|
if expire:
|
||
|
data["expire"] = expire
|
||
|
|
||
|
response = requests.post(url, data=data)
|
||
|
|
||
|
if response.status_code == 200:
|
||
|
return response.text.strip() # Return the paste URL
|
||
|
else:
|
||
|
return f"Error: {response.text.strip()}"
|
||
|
|
||
|
# Example usage:
|
||
|
# result = paste_to_centos("This is a test paste", title="Test", name="John Doe", lang="python")
|
||
|
# print(result)
|