google converts csv to md table

master
Bel LaPointe 2022-02-16 14:35:19 -07:00
parent 98df3f2372
commit c0d49d23bb
1 changed files with 15 additions and 11 deletions

View File

@ -18,29 +18,33 @@ google() (
}
get() {
local cache_key="google get $*"
if cache get "$cache_key"; then
return 0
fi
_get "$@" | cache put "$cache_key"
}
_get() {
local url="$1"
local id="${url%/*}"
id="${id##*/}"
local downloaded="$(rclone get_google "$id")"
echo "# ${downloaded##*/}"
echo ""
if [ "${downloaded##*.}" == ".csv" ]; then
if [ "${downloaded##*.}" == "csv" ]; then
_csv_to_md "$downloaded"
fi
else
cat "$downloaded"
fi
}
_csv_to_md() {
local f="$1"
log _csv_to_md $f
(
head -n 1 "$f"
head -n 1 "$f" \
| sed 's/^[^,][^,]*/--- /' \
| sed 's/[^,][^,]*$/ ---/' \
| sed 's/,[^,][^,]*/, --- /g' \
| sed 's/[^|]$/|/'
tail -n +2 "$f"
) \
| grep . \
| sed 's/,/ | /g' \
| sed 's/^/| /'
}
expand() {