catto!
This commit is contained in:
parent
2be2733c1b
commit
ce71de8abd
58
configs/scripts/catto
Executable file
58
configs/scripts/catto
Executable file
@ -0,0 +1,58 @@
|
||||
#! /usr/bin/env python3
|
||||
import sys
|
||||
import requests
|
||||
import json
|
||||
import argparse
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
import netrc
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("image", help="Image to upload")
|
||||
ap.add_argument("--no-compress", help="Don't compress the image", action="store_true")
|
||||
args = ap.parse_args()
|
||||
|
||||
# Load the API key from the .netrc file
|
||||
if "catto.pictures" not in netrc.netrc().hosts:
|
||||
print("No catto.pictures entry in .netrc file")
|
||||
return 1
|
||||
login, account, password = netrc.netrc().authenticators("catto.pictures")
|
||||
|
||||
# Parse the image to a path
|
||||
image_path = Path(args.image)
|
||||
|
||||
# Ensure the file actually exists
|
||||
if not image_path.exists():
|
||||
print("File not found", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
# Compres the image to a temporary file
|
||||
with tempfile.NamedTemporaryFile(suffix=image_path.suffix) as temp:
|
||||
# Compress
|
||||
if not args.no_compress:
|
||||
os.system(f"convert {image_path} -quality 25% {temp.name}")
|
||||
image_path = Path(temp.name)
|
||||
|
||||
# Strip all exif data
|
||||
os.system(f"exiftool -EXIF= {image_path}")
|
||||
|
||||
# Upload the image
|
||||
with open(image_path, "rb") as f:
|
||||
r = requests.post(
|
||||
"https://upload.catto.pictures",
|
||||
files={"image": (temp.name, f, f"image/{image_path.suffix[1:]}")},
|
||||
headers={
|
||||
"Authorization": password,
|
||||
"Domain": "img.ewpratten.com",
|
||||
}
|
||||
)
|
||||
if r.status_code != 200:
|
||||
print(f"Error uploading image:\n{r.text}", file=sys.stderr)
|
||||
return 1
|
||||
print(json.loads(r.text)["url"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
@ -15,6 +15,3 @@ fi
|
||||
|
||||
# I always want my ~/bin to be in my PATH
|
||||
export PATH="$HOME/bin:$PATH"
|
||||
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
|
||||
export SDKMAN_DIR="$HOME/.sdkman"
|
||||
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||
|
@ -4,6 +4,12 @@
|
||||
|
||||
- clean: ['~']
|
||||
|
||||
- create:
|
||||
- ~/Downloads
|
||||
- ~/bin
|
||||
- ~/projects
|
||||
- ~/src
|
||||
|
||||
- link:
|
||||
~/.gitconfig: configs/git/.gitconfig
|
||||
~/.zshrc:
|
||||
@ -12,12 +18,10 @@
|
||||
~/.config/tabset: configs/tabset
|
||||
~/.local/share/remmina: configs/remmina/hosts
|
||||
~/.config/nvim: configs/nvim
|
||||
|
||||
- create:
|
||||
- ~/Downloads
|
||||
- ~/bin
|
||||
- ~/projects
|
||||
- ~/src
|
||||
~/bin/catto:
|
||||
path: configs/scripts/catto
|
||||
mode: 755
|
||||
|
||||
- shell:
|
||||
- [git submodule update --init --recursive, Installing submodules]
|
||||
- [git submodule update --init --recursive, Installing submodules]
|
||||
- [chmod +x configs/scripts/catto, Making catto executable]
|
Loading…
x
Reference in New Issue
Block a user