Incorporated muna

master v1.0.0
Steven Saus 4 years ago
parent c703e323d0
commit 8bc3258a73
  1. 5
      README.md
  2. 4
      agaetr_parse.py
  3. 1
      agaetr_send.sh
  4. 1
      out_enabled/toot.sh
  5. 56
      standalone_sender.sh
  6. 106
      unredirector.sh
  7. 33
      unredirector_old.sh

@ -371,8 +371,9 @@ put these into cronjobs.
There are other files in this repository:
* `unredirector.sh` - Used by `agaetr` to remove redirections and shortening.
* `standalone_sender.sh` - Working on this to use the `agaetr` framework without RSS feeds; not ready for use yet.
* `unredirector.sh` - Used by `agaetr` to remove redirections and shortening. Exactly the same as [muna](https://github.com/uriel1998/muna).
* `unredirector_old.sh` - The original program/function used by `agaetr` to remove redirections and shortening.
* `standalone_sender.sh` - Working on this to use the `agaetr` framework without RSS feeds; not ready for use yet.
## 12. TODO

@ -81,7 +81,7 @@ def parse_that_feed(url,sensitive,CW,GCW):
post_description = post_description.replace('\n', ' ').replace('\r', '').replace('<p>', '').replace('</p>', '').replace('|', ' ')
splitter = post_description.split()
post_description =" ".join(splitter)
post_description =BeautifulSoup(post_description, "lxml").text
post_description =BeautifulSoup(post_description, 'html.parser').text
else:
post_description = ""
else:
@ -91,7 +91,7 @@ def parse_that_feed(url,sensitive,CW,GCW):
post_description = post_description.replace('\n', ' ').replace('\r', '').replace('<p>', '').replace('</p>', '').replace('|', ' ')
splitter = post_description.split()
post_description =" ".join(splitter)
post_description =BeautifulSoup(post_description, "lxml").text
post_description =BeautifulSoup(post_description, 'html.parser').text
else:
post_description = ""

@ -83,7 +83,6 @@ if [ "$(ls -A "$SCRIPT_DIR/short_enabled")" ]; then
echo "No URL shortening performed."
else
if [ "$shortener" != ".keep" ];then
echo "FUCKNOW"
short_funct=$(echo "${shortener%.*}_shortener")
source "$SCRIPT_DIR/short_enabled/$shortener"
url="$link"

@ -0,0 +1 @@
/home/steven/documents/programming/agaetr/out_avail/toot.sh

@ -1,9 +1,55 @@
And also whether or not to shorten the thing needs to go here
And then once you have all these items, loops through the same way you do with
agaetr.
#!/bin/bash
#get install directory
export SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
if [ ! -f "$HOME/.config/agaetr/agaetr.ini" ];then
echo "INI not located; betcha nothing else is set up."
exit 89
fi
#So here we need to get
# 1. today's date and time
# 2. String to send (title)
# 3. Image (if any) to send
# 4. imgalt - from local image? Maybe skip that for the moment
# 5. CWs if any
# Perhaps read from image metadata?
# ADDTL
# Gotta do this so that the other submodules work just fine
# Parse out link from string (if any exist)
# parse out tags from string (if any exist)
#ADDITIONAL: Should this go in the "buffer" or out immediately?
# And if you want to put it in "buffer", you can do so by adding it to the posts.db section
#20181227091253|Bash shell find out if a variable has NULL value OR not|https://www.cyberciti.biz/faq/bash-shell-find-out-if-a-variable-has-null-value-or-not/||None|None|#bash shell #freebsd #korn shell scripting #ksh shell #linux #unix #bash shell scripting #linux shell scripting #shell script
OIFS=$IFS
IFS='|'
myarr=($(echo "$instring"))
IFS=$OIFS
#pulling array into named variables so they work with sourced functions
# passing published time (from dd MMM)
posttime=$(echo "${myarr[0]}")
posttime2=${posttime::-6}
pubtime=$(date -d"$posttime2" +%d\ %b)
title=$(echo "${myarr[1]}" | sed 's|["]|“|g' | sed 's|['\'']|’|g' )
link=$(echo "${myarr[2]}")
cw=$(echo "${myarr[3]}")
imgurl=$(echo "${myarr[5]}")
imgalt=$(echo "${myarr[4]}" | sed 's|["]|“|g' | sed 's|['\'']|’|g' )
hashtags=$(echo "${myarr[6]}")
description=$(echo "${myarr[7]}" | sed 's|["]|“|g' | sed 's|['\'']|’|g' )
And if you want to put it in "buffer", you can do so by adding it to the
posts.db section
This would be useful for just posting or for perhaps newsboat, etc

@ -1,33 +1,117 @@
#!/bin/bash
# because this is a bash function, it's using the variable $url as the returned
# variable. So there's no real "return" other than setting that var.
function unredirector {
headers=$(curl --fail --connect-timeout 20 --location -sS --head "$url")
#Explainer/reminder - curl will return 404 error codes *unless* you have
# --fail set, in which case you get the error code. That's done here so
# that it handles 404 and missing server exactly the same way, while
# letting the 300 level codes pass through normally.
headers=$(curl -k -s --fail --connect-timeout 20 --location -sS --head "$url")
code=$(echo "$headers" | head -1 | awk '{print $2}')
#check for null as well
#checks for null as well
if [ -z "$code" ];then
echo "[info] Web page is gone!" >&2;
if [ $OUTPUT = 1 ];then
echo "[info] Page/server not found, trying Internet Archive" >&2;
fi
firsturl="$url"
#In the JSON the Internet Archive returns, the string
# "archived_snapshots": {}
# is returned if it does not exist in the Archive either.
api_ia=$(curl -s http://archive.org/wayback/available?url="$url")
NotExists=$(echo "$api_ia" | grep -c -e '"archived_snapshots": {}')
if [ "$NotExists" != "0" ];then
SUCCESS=1 #that is, not a success
if [ $OUTPUT = 1 ];then
echo "[error] Web page is gone and not in Internet Archive!" >&2;
echo "[error] For page $firsturl" >&2;
unset -v $url
unset -v $firsturl
fi
else
if [ $OUTPUT = 1 ];then
echo "[info] Fetching Internet Archive version of" >&2;
echo "[info] page $firsturl" >&2;
fi
url=$(echo "$api_ia" | awk -F 'url": "' '{print $2}' 2>/dev/null | awk -F '", "' '{print $1}' | awk -F '"' '{print $1}')
unset -v $firsturl
fi
else
if echo "$code" | grep -q -e "3[0-9][0-9]";then
echo "[info] HTTP $code redirect" >&2;
if [ $OUTPUT = 1 ];then
echo "[info] HTTP $code redirect"
fi
resulturl=""
resulturl=$(wget -O- --server-response "$url" 2>&1 | grep "^Location" | tail -1 | awk -F ' ' '{print $2}')
resulturl=$(wget -T 20 -O- --server-response "$url" 2>&1 | grep "^Location" | tail -1 | awk -F ' ' '{print $2}')
if [ -z "$resulturl" ]; then
echo "[info] No new location found" >&2;
if [ $OUTPUT = 1 ];then
echo "[info] No new location found"
fi
resulturl=$(echo "$url")
else
echo "[info] New location found" >&2;
if [ $OUTPUT = 1 ];then
echo "[info] New location found"
fi
url=$(echo "$resulturl")
echo "[info] REprocessing $url" >&2;
headers=$(curl --connect-timeout 20 --location -sS --head "$url")
if [ $OUTPUT = 1 ];then
echo "[info] REprocessing $url"
fi
headers=$(curl -k -s --connect-timeout 20 --location -sS --head "$url")
code=$(echo "$headers" | head -1 | awk '{print $2}')
if echo "$code" | grep -q -e "3[0-9][0-9]";then
echo "[info] Second redirect; passing as-is" >&2;
if [ $OUTPUT = 1 ];then
echo "[info] Second redirect; passing as-is"
fi
fi
fi
fi
if echo "$code" | grep -q -e "2[0-9][0-9]";then
echo "[info] HTTP $code exists" >&2;
if [ $OUTPUT = 1 ];then
echo "[info] HTTP $code exists"
fi
fi
fi
}
##############################################################################
# Are we sourced?
# From http://stackoverflow.com/questions/2683279/ddg#34642589
##############################################################################
# Try to execute a `return` statement,
# but do it in a sub-shell and catch the results.
# If this script isn't sourced, that will raise an error.
$(return >/dev/null 2>&1)
# What exit code did that give?
if [ "$?" -eq "0" ];then
echo "[info] Function undirector ready to go."
OUTPUT=0
else
OUTPUT=1
if [ "$#" = 0 ];then
echo "Please call this as a function or with the url as the first argument."
else
if [ "$1" != "-q" ];then
url="$1"
else
url="$2"
OUTPUT=0
fi
SUCCESS=0
unredirector
if [ $SUCCESS -eq 0 ];then
# If it gets here, it has to be standalone
echo "$url"
else
exit 99
fi
fi
fi

@ -0,0 +1,33 @@
#!/bin/bash
function unredirector {
headers=$(curl --fail --connect-timeout 20 --location -sS --head "$url")
code=$(echo "$headers" | head -1 | awk '{print $2}')
#check for null as well
if [ -z "$code" ];then
echo "[info] Web page is gone!" >&2;
else
if echo "$code" | grep -q -e "3[0-9][0-9]";then
echo "[info] HTTP $code redirect" >&2;
resulturl=""
resulturl=$(wget -O- --server-response "$url" 2>&1 | grep "^Location" | tail -1 | awk -F ' ' '{print $2}')
if [ -z "$resulturl" ]; then
echo "[info] No new location found" >&2;
resulturl=$(echo "$url")
else
echo "[info] New location found" >&2;
url=$(echo "$resulturl")
echo "[info] REprocessing $url" >&2;
headers=$(curl --connect-timeout 20 --location -sS --head "$url")
code=$(echo "$headers" | head -1 | awk '{print $2}')
if echo "$code" | grep -q -e "3[0-9][0-9]";then
echo "[info] Second redirect; passing as-is" >&2;
fi
fi
fi
if echo "$code" | grep -q -e "2[0-9][0-9]";then
echo "[info] HTTP $code exists" >&2;
fi
fi
}
Loading…
Cancel
Save