2023-04-04 09:15:28 +03:00
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import hashlib
|
|
|
|
import re
|
|
|
|
|
2023-04-04 22:55:16 +03:00
|
|
|
URL = 'http://sprunge.us'
|
|
|
|
NAME = 'sprunge'
|
|
|
|
|
|
|
|
def get_service_tag():
|
|
|
|
return NAME
|
|
|
|
|
2023-04-04 09:15:28 +03:00
|
|
|
|
|
|
|
def upload(data):
|
|
|
|
try:
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
|
|
|
|
|
|
|
# Send the HTTP POST request to the Sprunge API
|
2023-04-04 22:55:16 +03:00
|
|
|
response = requests.post(URL, data={'sprunge': json_data})
|
2023-04-04 09:15:28 +03:00
|
|
|
if response.status_code == 200:
|
|
|
|
|
|
|
|
# Get the URL of the uploaded text from the response body
|
|
|
|
sprunge_url = response.text.strip()
|
|
|
|
|
|
|
|
#print('Uploaded to:', sprunge_url)
|
|
|
|
|
|
|
|
# Use a regular expression to extract the random ID from the URL
|
|
|
|
match = re.match(r'^http://sprunge\.us/(\w+)$', sprunge_url)
|
|
|
|
if match:
|
|
|
|
random_id = match.group(1)
|
|
|
|
#print('Random ID:', random_id)
|
|
|
|
key = "sprunge_" + random_id + '_' + md5sum[:5]
|
|
|
|
else:
|
|
|
|
print('Invalid Sprunge URL:', sprunge_url)
|
|
|
|
|
|
|
|
return {
|
|
|
|
"service": "sprunge",
|
|
|
|
"name": key,
|
|
|
|
"key": sprunge_url,
|
|
|
|
"md5sum": md5sum
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
except requests.exceptions.RequestException:
|
|
|
|
return None
|