mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Add python helper equivalent to yunopaste
This commit is contained in:
parent
fe48c37ce4
commit
eb42a25ada
1 changed files with 29 additions and 0 deletions
29
src/yunohost/utils/yunopaste.py
Normal file
29
src/yunohost/utils/yunopaste.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import errno
|
||||||
|
|
||||||
|
from moulinette.core import MoulinetteError
|
||||||
|
|
||||||
|
def yunopaste(data):
|
||||||
|
|
||||||
|
paste_server = "https://paste.yunohost.org"
|
||||||
|
|
||||||
|
try:
|
||||||
|
r = requests.post("%s/documents" % paste_server, data=data)
|
||||||
|
except Exception as e:
|
||||||
|
raise MoulinetteError(errno.EIO,
|
||||||
|
"Something wrong happened while trying to paste data on paste.yunohost.org : %s" % str(e))
|
||||||
|
|
||||||
|
if r.status_code != 200:
|
||||||
|
raise MoulinetteError(errno.EIO,
|
||||||
|
"Something wrong happened while trying to paste data on paste.yunohost.org : %s" % r.text)
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = json.loads(r.text)["key"]
|
||||||
|
except:
|
||||||
|
raise MoulinetteError(errno.EIO,
|
||||||
|
"Uhoh, couldn't parse the answer from paste.yunohost.org : %s" % r.text)
|
||||||
|
|
||||||
|
return "%s/raw/%s" % (paste_server, url)
|
Loading…
Add table
Reference in a new issue