Introduction
Introduction Statistics Contact Development Disclaimer Help
Add annna-add-hashtag script. - annna - Annna the nice friendly bot.
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
commit a6dcadfdfe85e7056b35f76ff25773a2d9fe43a6
parent 4890d6ecf11ff49bbe5d64460babe7e2adf146aa
Author: Annna Robert-Houdin <[email protected]>
Date: Sat, 28 Dec 2019 22:54:36 +0100
Add annna-add-hashtag script.
Diffstat:
A annna-add-hashtag | 121 +++++++++++++++++++++++++++++…
1 file changed, 121 insertions(+), 0 deletions(-)
---
diff --git a/annna-add-hashtag b/annna-add-hashtag
@@ -0,0 +1,121 @@
+#!/bin/sh
+
+memecachedir="/br/gopher/memecache"
+hashtagdb="/home/annna/bin/modules/hashtags/hashtags.txt"
+unprocessed="$(pwd)/unprocessed.txt"
+
+[ ! -e "${hashtagdb}" ] && touch "${hashtagdb}"
+
+dltag() {
+ tag="$1"
+ uri="$2"
+
+ grep "${tag} " $hashtagdb >/dev/null
+ if [ $? -eq 0 ];
+ then
+ printf "tag '%s' already in db.\n" "${tag}" >&2
+ printf "%s %s\n" "${tag}" "${uri}" >> "${unprocessed}"
+ return 1
+ fi
+ stag="$(printf "${tag}\n" | cut -c 2-)"
+
+ cd "${memecachedir}"
+ error=0
+ case "$uri" in
+ *youtube.com*|*youtu.be*|*dumpert.nl*|*vimeo.com*)
+ youtube-dl -o "${stag}.%(ext)s" "${uri}"
+ if [ $? -gt 0 ];
+ then
+ error=1
+ printf "youtube-dl tag '%s' had problems.\n" "${tag}" …
+ printf "%s %s\n" "${tag}" "${uri}" >> "${unprocessed}"
+ fi
+ ;;
+ gopher://bitreich.org/*)
+ ;;
+ *)
+ ext="$(basename "${uri}" | sed 's/^.*\.//')"
+ curl -o "${stag}.${ext}" "${uri}"
+ if [ $? -gt 0 ];
+ then
+ error=1
+ printf "curl tag '%s' had problems.\n" "${tag}" >&2
+ printf "%s %s\n" "${tag}" "${uri}" >> "${unprocessed}"
+ fi
+ ;;
+ esac
+ if [ $error -eq 0 ];
+ then
+ printf "tag '%s' downloaded.\n" "${tag}" >&2
+ printf "%s\n" "${uri}" > "${stag}.orig"
+ fi
+
+ return $error
+}
+
+inserttag() {
+ tag="$1"
+ uri="$2"
+
+ grep "${tag} " $hashtagdb >/dev/null
+ if [ $? -eq 0 ];
+ then
+ printf "tag '%s' already in db.\n" "${tag}" >&2
+ printf "%s %s\n" "${tag}" "${uri}" >> "${unprocessed}"
+ return 1
+ fi
+
+ stag="$(printf "${tag}\n" | cut -c 2-)"
+ cd "${memecachedir}"
+ tagfile="$(basename "$(find . -name "${stag}.*" | grep -v .orig)")"
+ case "${tagfile}" in
+ *.jpg|*.JPG|*.jpeg|*.JPEG|*.png|*.PNG|*.svg|*.SVG)
+ tagtype="I"
+ ;;
+ *.gif|*.GIF)
+ tagtype="g"
+ ;;
+ *.txt|*.TXT|*.vt|*.VT)
+ tagtype="0"
+ ;;
+ *)
+ tagtype="9"
+ ;;
+ esac
+ memecacheuri="gopher://bitreich.org/${tagtype}/memecache/${tagfile}"
+
+ printf "%s %s\n" "${tag}" "${memecacheuri}" >> "${hashtagdb}"
+ printf "tag '%s' added as '%s' to hashtags db.\n" "${tag}" "${memecach…
+}
+
+addtag() {
+ tag="$1"
+ uri="$2"
+
+ dltag "$1" "$2"
+ [ $? -gt 0 ] && return
+ inserttag "$1" "$2"
+}
+
+if [ $# -eq 2 ];
+then
+ tag="$1"
+ uri="$2"
+
+ addtag "${tag}" "${uri}"
+else
+ if [ $# -eq 1 ];
+ then
+ [ -e "$1" ] && cat "$1" \
+ | while read -r tag uri;
+ do
+ addtag "${tag}" "${uri}"
+ done
+ else
+ while read -r tag uri;
+ do
+ addtag "${tag}" "${uri}"
+ done
+ fi
+fi
+
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.