Last active
August 7, 2024 13:30
-
-
Save lopes/4436870 to your computer and use it in GitHub Desktop.
An obsolete implementation of Fortunes. It reads the last Pensador's tweet, store it and display for the user. 1 tweet a day. #linux #conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#webfortune.sh | |
# Retrieves the last @pensador's tweet. Manages it retrieving one | |
# tweet per day, by using a file to cache the quote. | |
# | |
# | |
# José Lopes de O. Júnior <http://indiecode.com.br> | |
# | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
# Global Variables | |
# | |
TODAY=$(date +%Y%m%d) | |
FILE="$HOME/.pensador" | |
file_feed(){ | |
# | |
# Feeds the file with a new quote. | |
# If the new quote is equal to the old, do nothing. | |
# | |
local quot=$(get_tweet) | |
[ -z "$quot" ] && return 1 | |
[ "$quot" != "$(file_get_quot)" ] && echo -e "$TODAY\n$quot" > $FILE | |
return $? | |
} | |
# | |
# Retrives the date and the quote from the file. | |
# | |
file_get_date(){ head -n 1 $FILE; } | |
file_get_quot(){ echo; tail -1 $FILE; echo; } | |
get_tweet(){ | |
# | |
# Gets the @pensador's last tweet. | |
# | |
local url="http://twitter.com/statuses/user_timeline/25989479.rss" | |
curl -s --connect-timeout 5 "$url" | | |
grep -m 2 "<description>" | | |
tail -1 | | |
cut -d ":" -f2- | | |
sed -e "# Removes spaces at the begin | |
s/^ *// | |
# Formats the end | |
s/<\/description>$/ --@pensador/ | |
# ISO 8859-1 Characters - Substitution | |
s/À/À/g; s/Á/Á/g; s/Â/Â/g; s/Ã/Ã/g; | |
s/Ä/Ä/g; s/Å/Å/g; s/Æ/Æ/g; s/Ç/Ç/g; | |
s/È/È/g; s/É/É/g; s/Ê/Ê/g; s/Ë/Ë/g; | |
s/Ì/Ì/g; s/Í/Í/g; s/Î/Î/g; s/Ï/Ï/g; | |
s/Ð/Ð/g; s/Ñ/Ñ/g; s/Ò/Ò/g; s/Ó/Ó/g; | |
s/Ô/Ô/g; s/Õ/Õ/g; s/Ö/Ö/g; s/Ø/Ø/g; | |
s/Ù/Ù/g; s/Ú/Ú/g; s/Û/Û/g; s/Ü/Ü/g; | |
s/Ý/Ý/g; s/Þ/Þ/g; s/ß/ß/g; s/à/à/g; | |
s/á/á/g; s/â/â/g; s/ã/ã/g; s/ä/ä/g; | |
s/å/å/g; s/æ/æ/g; s/ç/ç/g; s/è/è/g; | |
s/é/é/g; s/ê/ê/g; s/ë/ë/g; s/ì/ì/g; | |
s/í/í/g; s/î/î/g; s/ï/ï/g; s/ð/ð/g; | |
s/ñ/ñ/g; s/ò/ò/g; s/ó/ó/g; s/ô/ô/g; | |
s/õ/õ/g; s/ö/ö/g; s/ø/ø/g; s/ù/ù/g; | |
s/ú/ú/g; s/û/û/g; s/ü/ü/g; s/ý/ý/g; | |
s/þ/þ/g; s/ÿ/ÿ/g" | |
} | |
# | |
# Main | |
# | |
default="19700101\nA natureza detesta o vazio. --Blaise Pascal" | |
[ -f "$FILE" ] || echo -e "$default" > $FILE | |
[ "$TODAY" != "$(file_get_date)" ] && file_feed | |
file_get_quot | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment