Better organization of them files. Added bpa.st support (paste.python.org).

This commit is contained in:
kalzu rekku 2024-07-28 13:23:16 +03:00
parent fa369d636f
commit 9d950f6a3f
11 changed files with 270 additions and 89 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
__pycache__/
*.txt
foo.py

47
gen_test_upload.py Normal file
View File

@ -0,0 +1,47 @@
import re
import os
from random import randrange
def new_upload(output_file):
"""
Extracts 1 to 3 sentences from input_file and writes them to output_file.
"""
num_sentences = randrange(1, 4)
input_file = '../HP1.txt'
index_file = '../read_index.txt'
def read_sentences(file_path, start_index, num_sentences):
sentences = []
with open(file_path, 'r') as file:
text = file.read()
sentences = re.split(r'(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\?)\s', text)
return sentences[start_index:start_index + num_sentences], start_index + num_sentences
def write_sentences(sentences, output_path):
with open(output_path, 'w') as file:
for sentence in sentences:
file.write(sentence + ' ')
def read_index(index_file):
if not os.path.exists(index_file):
return 0
with open(index_file, 'r') as file:
return int(file.read().strip())
def write_index(index_file, index):
with open(index_file, 'w') as file:
file.write(str(index))
# Read the current index
start_index = read_index(index_file)
# Read 1 to 3 sentences from the input file
sentences, new_index = read_sentences(input_file, start_index, num_sentences)
# Write the sentences to the output file
write_sentences(sentences, output_file)
# Write the new index back to the index file
write_index(index_file, new_index)
print(f"Successfully wrote {len(sentences)} sentence(s) to {output_file}.")

View File

@ -1,89 +1,10 @@
import requests
import secrets
import base64
import tempfile
import socket
import os
from cpaste import publish_to_cpaste
def publish_to_termbin(content):
host = 'termbin.com'
port = 9999
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
sock.sendall(content.encode('utf-8'))
response = sock.recv(1024).decode('utf-8').strip()
sock.close()
return response
except Exception as e:
print(f"Error connecting to Termbin: {e}")
return None
def publish_to_mozilla(content):
url = 'https://pastebin.mozilla.org/api/'
data = {
'content': content,
'expires': '86400', # 24 hours
'format': 'text',
'lexer': '_text'
}
response = requests.post(url, data=data)
if response.status_code == 200:
# Mozilla returns full link to the paste
return f"{response.text}"
return None
def publish_to_dpaste(content):
url = 'https://dpaste.org/api/'
data = {
'content': content,
'format': 'url'
}
response = requests.post(url, data=data)
if response.status_code == 200:
return response.text.strip()
return None
def publish_to_pastesh(content):
HOST = 'https://paste.sh'
VERSION = 'v2'
# Generate ID
id = f"p{secrets.token_urlsafe(6)}"
# Create a temporary file
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp_file:
temp_file_path = temp_file.name
# Write content to the temporary file
temp_file.write(content)
temp_file.flush()
try:
# Prepare headers
headers = {
'X-Server-Key': '',
'Content-type': f'text/vnd.paste.sh-{VERSION}'
}
# Send the request
with open(temp_file_path, 'rb') as file:
response = requests.post(f"{HOST}/{id}", headers=headers, data=file)
if response.status_code == 200:
return f"{HOST}/{id}"
else:
print(f"Error: Status code {response.status_code}")
print(f"Response: {response.text}")
return None
finally:
# Clean up the temporary file
os.unlink(temp_file_path)
from pastebins.cpaste import publish_to_cpaste
from pastebins.paste_python import publish_to_pinnwand
from pastebins.termbin import publish_to_termbin
from pastebins.paste_mozilla import publish_to_mozilla
from pastebins.dpaste import publish_to_dpaste
from gen_test_upload import new_upload
def publish_to_multiple_pastebins(file_path):
# Read the file content
@ -112,13 +33,19 @@ def publish_to_multiple_pastebins(file_path):
if cpaste_url:
results['CPaste'] = cpaste_url
# Publish to paste python org
pbin_url = publish_to_pinnwand(file_content)
if pbin_url:
results['pbin'] = pbin_url
return results
# Example usage
# Make new file to upload and then upload it to all the pastebins
file_path = 'test.txt'
new_upload(file_path)
results = publish_to_multiple_pastebins(file_path)
# Print the return links from the pastebins
for service, url in results.items():
print(f"{service}: {url}")

View File

@ -0,0 +1,41 @@
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)

View File

@ -0,0 +1,28 @@
import requests
def upload_to_paste_debian(content: str) -> str:
# The URL for the paste service
url = 'https://paste.debian.net/'
# Data payload
data = {
'format': 'text', # You can also use 'text' if you want to enforce plain text format
'content': content,
'submit': 'Send'
}
# Send the POST request to paste.debian.net
response = requests.post(url, data=data)
# Check if the request was successful
if response.status_code == 200:
# If successful, extract the paste URL from the response
print(response.content)
paste_url = response.url
return paste_url
else:
raise Exception(f"Failed to upload to paste.debian.net, status code: {response.status_code}")

42
not_working/pastesh.py Normal file
View File

@ -0,0 +1,42 @@
import tempfile
import secrets
import requests
import os
def publish_to_pastesh(content):
HOST = 'https://paste.sh'
VERSION = 'v2'
# Generate ID
id = f"p{secrets.token_urlsafe(6)}"
# Create a temporary file
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp_file:
temp_file_path = temp_file.name
# Write content to the temporary file
temp_file.write(content)
temp_file.flush()
try:
# Prepare headers
headers = {
'X-Server-Key': '',
'Content-type': f'text/vnd.paste.sh-{VERSION}'
}
# Send the request
with open(temp_file_path, 'rb') as file:
response = requests.post(f"{HOST}/{id}", headers=headers, data=file)
if response.status_code == 200:
return f"{HOST}/{id}"
else:
print(f"Error: Status code {response.status_code}")
print(f"Response: {response.text}")
return None
finally:
# Clean up the temporary file
os.unlink(temp_file_path)

View File

@ -216,8 +216,8 @@ def privatebin_send(paste_url,
paste_url_id = result['url']
paste_deletetoken = result['deletetoken']
print('Delete paste: %s/?pasteid=%s&deletetoken=%s' %
(paste_url, paste_id, paste_deletetoken))
# print('Delete paste: %s/?pasteid=%s&deletetoken=%s' %
# (paste_url, paste_id, paste_deletetoken))
# print('')
# print('### Paste (%s): %s%s#%s' %
# (paste_formatter,

13
pastebins/dpaste.py Normal file
View File

@ -0,0 +1,13 @@
import requests
def publish_to_dpaste(content):
url = 'https://dpaste.org/api/'
data = {
'content': content,
'format': 'url'
}
response = requests.post(url, data=data)
if response.status_code == 200:
return response.text.strip()
return None

View File

@ -0,0 +1,16 @@
import requests
def publish_to_mozilla(content):
url = 'https://pastebin.mozilla.org/api/'
data = {
'content': content,
'expires': '86400', # 24 hours
'format': 'text',
'lexer': '_text'
}
response = requests.post(url, data=data)
if response.status_code == 200:
# Mozilla returns full link to the paste
return f"{response.text}"
return None

48
pastebins/paste_python.py Normal file
View File

@ -0,0 +1,48 @@
import requests
def publish_to_pinnwand(content: str, expiry: str = "1day", lexer: str = "text", name: str = None, base_url: str = "https://bpa.st") -> str:
"""
Uploads content to pinnwand pastebin and returns the link to the paste.
Args:
- content: The content of the paste.
- expiry: Expiry time for the paste. Defaults to "1day".
- lexer: The lexer to use for syntax highlighting. Defaults to "text".
- name: Optional name for the file.
- base_url: The base URL of the pinnwand instance. Defaults to "https://bpa.st".
Returns:
- The URL of the created paste.
"""
# API endpoint for creating new pastes
api_endpoint = f"{base_url}/api/v1/paste"
# Create the payload
payload = {
"expiry": expiry,
"files": [
{
"lexer": lexer,
"content": content
}
]
}
# Add the name field if provided
if name:
payload["files"][0]["name"] = name
# Send the POST request to the API
response = requests.post(api_endpoint, json=payload)
# Check if the request was successful
if response.status_code == 200:
# Parse the response JSON
response_data = response.json()
paste_url = response_data.get("link")
return paste_url
else:
raise Exception(f"Failed to upload to pinnwand, status code: {response.status_code}, message: {response.text}")

18
pastebins/termbin.py Normal file
View File

@ -0,0 +1,18 @@
import socket
"""
Super simple termbin client
"""
def publish_to_termbin(content):
host = 'termbin.com'
port = 9999
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
sock.sendall(content.encode('utf-8'))
response = sock.recv(1024).decode('utf-8').strip()
sock.close()
return response
except Exception as e:
print(f"Error connecting to Termbin: {e}")
return None