lots of improvements to pastedb01
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,22 +1,34 @@
|
||||
"""
|
||||
This module defines functions to interact with the p.defau.lt service for uploading and retrieving code snippets.
|
||||
|
||||
Functions:
|
||||
- get_service_tag(): Returns a string representing the service tag for p.defau.lt.
|
||||
- upload(data): Uploads a code snippet to p.defau.lt and returns a dictionary containing metadata about the upload.
|
||||
- get(trace): Retrieves the code snippet associated with the provided trace from p.defau.lt.
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
def serviceTag():
|
||||
URL = 'https://p.defau.lt/submit.php'
|
||||
NAME_PREFIX = 'defau_'
|
||||
|
||||
def get_service_tag():
|
||||
return 'p.defau.lt'
|
||||
|
||||
def upload(data):
|
||||
json_data = json.dumps(data)
|
||||
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
||||
|
||||
url = 'https://p.defau.lt/submit.php'
|
||||
response = requests.post(url, data={'code': json_data})
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
response = requests.post(URL, data={'code': json_data})
|
||||
response.raise_for_status()
|
||||
key = response.url
|
||||
name = 'defau_' + md5sum[:5]
|
||||
return {'name': name, 'service': 'p.defau.lt', 'key': key, 'md5sum': md5sum}
|
||||
else:
|
||||
name = f"{NAME_PREFIX}{md5sum[:5]}"
|
||||
return {'name': name, 'service': get_service_tag(), 'key': key, 'md5sum': md5sum}
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
def get(trace):
|
||||
|
@ -2,6 +2,11 @@ import hashlib
|
||||
import json
|
||||
import requests
|
||||
|
||||
NAME = 'dpaste'
|
||||
|
||||
def get_service_tag():
|
||||
return NAME
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
content = json.dumps(data)
|
||||
@ -20,10 +25,10 @@ def upload(data):
|
||||
md5sum = hashlib.md5(content.encode('utf-8')).hexdigest()
|
||||
|
||||
return {
|
||||
'service': 'dpaste',
|
||||
'service': NAME,
|
||||
'key': dpaste_url,
|
||||
'md5sum': md5sum,
|
||||
'name': 'dpaste_' + dpaste_url.rsplit('/', 1)[-1]
|
||||
'name': NAME + '_' + dpaste_url.rsplit('/', 1)[-1]
|
||||
}
|
||||
else:
|
||||
return None
|
||||
|
@ -2,7 +2,11 @@ import requests
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
url = 'https://paste.opendev.org/json/'
|
||||
URL = 'https://paste.opendev.org/json/'
|
||||
NAME = 'opendev'
|
||||
|
||||
def get_service_tag():
|
||||
return NAME
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
@ -17,7 +21,7 @@ def upload(data):
|
||||
}
|
||||
|
||||
# send request to create new paste
|
||||
response = requests.post(url + '?method=pastes.newPaste', json=payload)
|
||||
response = requests.post(URL + '?method=pastes.newPaste', json=payload)
|
||||
|
||||
status = response.status_code
|
||||
paste_id = response.json()['data']
|
||||
@ -27,10 +31,10 @@ def upload(data):
|
||||
md5sum = hashlib.md5(content.encode('utf-8')).hexdigest()
|
||||
|
||||
return {
|
||||
'service': "opendev",
|
||||
'key': url,
|
||||
'service': NAME,
|
||||
'key': URL[:-6],
|
||||
'md5sum': md5sum,
|
||||
'name': 'opendev_' + paste_id + '_' + md5sum[:5]
|
||||
'name': NAME + '_' + paste_id + '_' + md5sum[:5]
|
||||
}
|
||||
else:
|
||||
return None
|
||||
|
@ -2,6 +2,13 @@ import requests
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
|
||||
URL = 'https://pastie.io/documents'
|
||||
NAME = 'pastie'
|
||||
|
||||
def get_service_tag():
|
||||
return NAME
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
json_data = json.dumps(data)
|
||||
@ -13,8 +20,8 @@ def upload(data):
|
||||
# print(f'JSON object uploaded to Pastie: {pastie_url}')
|
||||
|
||||
return {
|
||||
"service": "pastie",
|
||||
"name": 'pastie_' + key,
|
||||
"service": NAME,
|
||||
"name": NAME + '_' + key,
|
||||
"key": pastie_url,
|
||||
"md5sum": md5sum
|
||||
}
|
||||
|
@ -4,9 +4,15 @@ import hashlib
|
||||
import re
|
||||
|
||||
|
||||
COMMAND = './external/rentry'
|
||||
NAME = 'rentry'
|
||||
|
||||
def get_service_tag():
|
||||
return NAME
|
||||
|
||||
def upload(data):
|
||||
md5sum = hashlib.md5(json.dumps(data).encode('utf-8')).hexdigest()
|
||||
command = ['./external/rentry', 'new', json.dumps(data)]
|
||||
command = [ COMMAND, 'new', json.dumps(data)]
|
||||
output = subprocess.check_output(command, universal_newlines=True)
|
||||
#print(output)
|
||||
lines = output.strip().split('\n')
|
||||
|
@ -3,7 +3,12 @@ import json
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
url = 'http://sprunge.us'
|
||||
URL = 'http://sprunge.us'
|
||||
NAME = 'sprunge'
|
||||
|
||||
def get_service_tag():
|
||||
return NAME
|
||||
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
@ -11,7 +16,7 @@ def upload(data):
|
||||
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
||||
|
||||
# Send the HTTP POST request to the Sprunge API
|
||||
response = requests.post(url, data={'sprunge': json_data})
|
||||
response = requests.post(URL, data={'sprunge': json_data})
|
||||
if response.status_code == 200:
|
||||
|
||||
# Get the URL of the uploaded text from the response body
|
||||
|
Reference in New Issue
Block a user