26 lines
757 B
Python
26 lines
757 B
Python
|
import requests
|
||
|
import json
|
||
|
import hashlib
|
||
|
|
||
|
def upload(data):
|
||
|
try:
|
||
|
json_data = json.dumps(data)
|
||
|
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
||
|
response = requests.post('https://pastie.io/documents', data=json_data)
|
||
|
if response.status_code == 200:
|
||
|
key = response.json()['key']
|
||
|
pastie_url = f'https://pastie.io/{key}'
|
||
|
# print(f'JSON object uploaded to Pastie: {pastie_url}')
|
||
|
|
||
|
return {
|
||
|
"service": "pastie",
|
||
|
"name": 'pastie_' + key,
|
||
|
"key": pastie_url,
|
||
|
"md5sum": md5sum
|
||
|
}
|
||
|
else:
|
||
|
return None
|
||
|
except requests.exceptions.RequestException:
|
||
|
return None
|
||
|
|