Moved scripts

This commit is contained in:
Brandon Rozek 2023-01-05 01:01:55 -05:00
parent 8a2c03a69b
commit 15c038f9ff
No known key found for this signature in database
GPG key ID: 26E457DA82C9F480
5 changed files with 0 additions and 0 deletions

27
scripts/LLA2WPT.sh Executable file
View file

@ -0,0 +1,27 @@
#!/bin/sh
set -o errexit
set -o nounset
set -o pipefail
show_usage() {
echo "Usage: LLA2WPT.sh [LAT] [LON] [ALT] [?NAME]"
exit 1
}
# Check argument count
if [ "$#" -ne 3 ] | [ "$#" -ne 4 ]; then
show_usage
fi
LAT="$1"
LON="$2"
ALT="$3"
NAME=${4-""}
echo "<wpt lat=\"$LAT\" lon=\"$LON\">"
echo -e "\t<ele>$ALT</ele>"
echo -e "\t<name>$4</name>"
echo "</wpt>"

63
scripts/archive_toot.py Executable file
View file

@ -0,0 +1,63 @@
#!/usr/bin/env python
"""
Saves a toot to reference as a shortcode
in a post.
"""
from http.client import HTTPResponse
from urllib.parse import urlparse
from urllib import request
from typing import Optional
import argparse
import json
import sys
SAVE_DIR = "static/data/toots"
# Grab arguments
parser = argparse.ArgumentParser(description="Save a toot")
parser.add_argument("toot_url", type=str, help="URL to specific toot")
args = vars(parser.parse_args())
parsed_url = urlparse(args['toot_url'])
# Parse Arguments
SERVER = f"{parsed_url.scheme}://{parsed_url.netloc}"
TOOT_ID = parsed_url.path.split("/")[-1]
# Query server
url = SERVER + "/api/v1/statuses/" + TOOT_ID
response: Optional[HTTPResponse] = None
try:
response = request.urlopen(url)
except Exception:
print("Unable to grab toots from Mastodon.")
if response is None:
sys.exit(-1)
# Parse server response
server_data: Optional[dict] = None
try:
server_data = json.loads(response.read())
except Exception:
print("Malformed JSON response from server.")
if server_data is None:
sys.exit(-1)
if not isinstance(server_data, dict):
print("Unexpected JSON response, should be of form dict.")
sys.exit(-1)
# Save toot
TOOT_REFERENCE = f"{parsed_url.netloc.replace('.', '-')}-{TOOT_ID}"
TOOT_SAVE_FILE = f"{SAVE_DIR}/{TOOT_REFERENCE}.json"
try:
with open(TOOT_SAVE_FILE, "w", encoding="UTF-8") as f:
json.dump(server_data, f)
except:
print("Unable to write to save location.")
sys.exit(-1)
print("Saved Toot Reference", TOOT_REFERENCE)

46
scripts/getLLA.sh Executable file
View file

@ -0,0 +1,46 @@
#!/bin/sh
set -o errexit
set -o nounset
set -o pipefail
show_usage() {
echo "Usage: getLLA.sh [imagefile]"
exit 1
}
# Check argument count
if [ "$#" -ne 1 ]; then
show_usage
fi
# Check that relevant command exist
if ! command -v identify > /dev/null; then
echo "Command identify from imagemagick not found. Exiting..."
fi
IMAGE_FILE="$1"
LAT=$(identify -format "%[EXIF:GPSLatitude]\n" "$IMAGE_FILE")
LAT_DIR=$(identify -format "%[EXIF:GPSLatitudeRef]\n" "$IMAGE_FILE")
LON=$(identify -format "%[EXIF:GPSLongitude]\n" "$IMAGE_FILE")
LON_DIR=$(identify -format "%[EXIF:GPSLongitudeRef]\n" "$IMAGE_FILE")
ALT=$(identify -format "%[EXIF:GPSAltitude]\n" "$IMAGE_FILE")
DegreesToDecimal() {
L0=$(echo "$1" | cut -d "," -f 1)
L1=$(echo "$1" | cut -d "," -f 2)
L2=$(echo "$1" | cut -d "," -f 3)
echo "scale=6;$L0 + $L1/60 + $L2/3600" | bc
}
LAT_DEC=$(DegreesToDecimal "$LAT")
LON_DEC=$(DegreesToDecimal "$LON")
ALT_DEC=$(echo "scale=6;$ALT" | bc)
LAT_PREFIX=$([ $LAT_DIR == "S" ] && echo "-" || echo "")
LON_PREFIX=$([ $LON_DIR == "W" ] && echo "-" || echo "")
echo "$LAT_PREFIX$LAT_DEC"
echo "$LON_PREFIX$LON_DEC"
echo "$ALT_DEC"

24
scripts/getWPT.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh
set -o errexit
set -o nounset
set -o pipefail
show_usage() {
echo "Usage: getWPT.sh [imagefile] [?name]"
exit 1
}
# Check argument count
if [ "$#" -ne 1 ]; then
show_usage
fi
getLLA="$(dirname $0)/getLLA.sh"
LLA=$("$getLLA" "$1" | tr " " "\n")
IMAGE_NAME="&lt;img src=&quot;$(basename "$1")&quot;/&gt;"
NAME_ARG=${2-""}
NAME=$([ "$NAME_ARG" != "" ] && echo "$NAME_ARG" || echo "$IMAGE_NAME")
echo -e "$LLA\n$NAME" | xargs -d "\n" $(dirname $0)/LLA2WPT.sh

37
scripts/jpg4web.bash Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
# 800px is the width of the content on my site
WIDTH=800
set -o errexit
set -o nounset
set -o pipefail
show_usage() {
echo "Usage: jpg4web.bash [imagefile]"
exit 1
}
# Check argument count
if [ "$#" -ne 1 ]; then
show_usage
fi
# Check that it ends in .jpg
if [[ "$1" != *.jpg ]]; then
echo "Argument [imagefile] must end in .jpg"
show_usage
fi
# Check that relevant commands exist
if ! command -v mogrify > /dev/null; then
echo "Command magick not found. Exiting..."
fi
if ! command -v jpegoptim > /dev/null; then
echo "Command jpegoptim not found. Exiting..."
fi
cp "$1" "$1.bak"
mogrify -resize "$WIDTH" "$1"
jpegoptim "$1"