chatgpt/pastedb/pastedb01/services/termbin.py

27 lines
839 B
Python

import subprocess
import hashlib
import time
import random
import string
def generate_name():
"""Generate a random name for the paste"""
ts = int(time.time())
rand_str = ''.join(random.choices(string.ascii_lowercase, k=5))
name = f"termbin-{ts}-{rand_str}"
return name
def upload(data):
"""Upload the data to termbin.com"""
name = generate_name()
try:
cmd = f"echo '{data}' | nc termbin.com 9999"
response = subprocess.check_output(cmd, shell=True, timeout=5).decode()
url = f"https://termbin.com/{name}"
md5sum = hashlib.md5(data.encode('utf-8')).hexdigest()
return {'service': 'termbin', 'key': url, 'md5sum': md5sum}
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
print(f"Upload failed with error: {e}")
return None