chatgpt/pastedb/pastedb01/services/rentry.py

23 lines
626 B
Python
Raw Normal View History

import subprocess
import json
import hashlib
import re
2023-04-04 22:55:16 +03:00
COMMAND = './external/rentry'
NAME = 'rentry'
def get_service_tag():
return NAME
def upload(data):
md5sum = hashlib.md5(json.dumps(data).encode('utf-8')).hexdigest()
2023-04-04 22:55:16 +03:00
command = [ COMMAND, 'new', json.dumps(data)]
output = subprocess.check_output(command, universal_newlines=True)
#print(output)
lines = output.strip().split('\n')
url = re.search("(?P<url>https?://[^\s]+)", lines[0]).group("url")
edit_code = lines[1].split(':')[-1].strip()
return {'name': 'rentry_' + edit_code, 'service': 'Rentry', 'key': url, 'md5sum': md5sum}