dotfiles/playbooks/roles/shell/templates/scripts/srht.py
Matej Focko 95a8a950b5
feat(zsh): add script for paste.sr.ht
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-11-19 15:14:47 +01:00

39 lines
973 B
Python
Executable file

#!/usr/bin/env python3
import os
import click
import requests
@click.command()
@click.option("--public", "visibility", flag_value="public")
@click.option("--unlisted", "visibility", flag_value="unlisted", default=True)
@click.option("--private", "visibility", flag_value="private")
@click.argument("src", type=click.File("r"), nargs=-1)
def paste(visibility, src):
request = {
"visibility": visibility,
"files": [
{"filename": s.name.split("/")[-1], "contents": s.read()}
for s in src
],
}
response = requests.post(
"https://paste.sr.ht/api/pastes",
json=request,
headers={"Authorization": f"token {os.getenv('SRHT_LEGACY')}"},
).json()
if "sha" in response:
click.secho(
f"Pasted: https://paste.sr.ht/~mfocko/{response['sha']}",
fg="green",
)
else:
click.secho(response, fg="red")
if __name__ == "__main__":
paste()