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)