40 lines
973 B
Python
40 lines
973 B
Python
|
#!/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()
|