2023-04-04 09:15:28 +03:00
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import hashlib
|
|
|
|
|
2023-04-04 22:55:16 +03:00
|
|
|
URL = 'https://paste.opendev.org/json/'
|
|
|
|
NAME = 'opendev'
|
|
|
|
|
|
|
|
def get_service_tag():
|
|
|
|
return NAME
|
2023-04-04 09:15:28 +03:00
|
|
|
|
|
|
|
def upload(data):
|
|
|
|
try:
|
|
|
|
content = json.dumps(data)
|
|
|
|
|
|
|
|
# create JSON payload for new paste
|
|
|
|
payload = {
|
|
|
|
'language': 'text',
|
|
|
|
'code': content,
|
|
|
|
'private': False
|
|
|
|
#'expire': '1day'
|
|
|
|
}
|
|
|
|
|
|
|
|
# send request to create new paste
|
2023-04-04 22:55:16 +03:00
|
|
|
response = requests.post(URL + '?method=pastes.newPaste', json=payload)
|
2023-04-04 09:15:28 +03:00
|
|
|
|
|
|
|
status = response.status_code
|
|
|
|
paste_id = response.json()['data']
|
|
|
|
|
|
|
|
if status == 200:
|
|
|
|
#print(f'JSON object uploaded to dpaste.com: {dpaste_url}')
|
|
|
|
md5sum = hashlib.md5(content.encode('utf-8')).hexdigest()
|
|
|
|
|
|
|
|
return {
|
2023-04-04 22:55:16 +03:00
|
|
|
'service': NAME,
|
|
|
|
'key': URL[:-6],
|
2023-04-04 09:15:28 +03:00
|
|
|
'md5sum': md5sum,
|
2023-04-04 22:55:16 +03:00
|
|
|
'name': NAME + '_' + paste_id + '_' + md5sum[:5]
|
2023-04-04 09:15:28 +03:00
|
|
|
}
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
except requests.exceptions.RequestException:
|
|
|
|
return None
|
|
|
|
# we can get the paste back by:
|
|
|
|
## $ > curl -d '{"paste_id":819463}' -H 'Content-Type: application/json' https://paste.opendev.org/json/?method=pastes.getPaste |jq .data.code
|