mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
* rewrite python * Modify to pipe * alexAubin review * Fix "output" var not existing ... * yunopaste: anonymize_output is too harsh and not yunopaste's job + print_usage ain't called ... * yunopaste: return link to the raw version, less confusing than haste's ui ... --------- Co-authored-by: Alexandre Aubin <alex.aubin@mailoo.org>
34 lines
808 B
Python
Executable file
34 lines
808 B
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import requests
|
|
import json
|
|
|
|
SERVER_URL = "https://paste.yunohost.org"
|
|
TIMEOUT = 3
|
|
|
|
def create_snippet(data):
|
|
try:
|
|
url = SERVER_URL + "/documents"
|
|
response = requests.post(url, data=data.encode('utf-8'), timeout=TIMEOUT)
|
|
response.raise_for_status()
|
|
dockey = json.loads(response.text)['key']
|
|
return SERVER_URL + "/raw/" + dockey
|
|
except requests.exceptions.RequestException as e:
|
|
print("\033[31mError: {}\033[0m".format(e))
|
|
sys.exit(1)
|
|
|
|
|
|
def main():
|
|
output = sys.stdin.read()
|
|
|
|
if not output:
|
|
print("\033[31mError: No input received from stdin.\033[0m")
|
|
sys.exit(1)
|
|
|
|
url = create_snippet(output)
|
|
|
|
print("\033[32mURL: {}\033[0m".format(url))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|