Created
June 7, 2020 07:22
-
-
Save miladev95/63205e79734b66919b1f8fce44fa8e42 to your computer and use it in GitHub Desktop.
shell script news reader
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/sh | |
reader(){ | |
if [ -z "$1" ];then | |
RSS_URL="https://www.khabaronline.ir/rss" | |
else | |
RSS_URL=$1 | |
fi | |
curl --silent "$RSS_URL" | \ | |
grep -E '(title>|description>|link>)' | \ | |
tail -n +4 | \ | |
sed -e 's/^[ \t]*//' | \ | |
if [[ $2 == "w" ]];then | |
sed -e 's/<title>//' -e 's/<\/title>//' -e 's/<description>/ /' -e 's/<\/description>//' -e 's/<link>//' -e 's/<\/link>//' > news.txt ; gedit news.txt & | |
else | |
sed -e 's/<title>//' -e 's/<\/title>//' -e 's/<description>/ /' -e 's/<\/description>//' -e 's/<link>//' -e 's/<\/link>//' | |
fi | |
} | |
############################### | |
starter(){ | |
PS3='Please enter your choice: ' | |
options=("read news and show in terminal" "read news and save into file and open file" "select news source" "Quit") | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
"read news and show in terminal") | |
reader | |
break | |
;; | |
"read news and save into file and open file") | |
reader "https://www.khabaronline.ir/rss" w | |
break | |
;; | |
"select news source") | |
echo 'Select site: ' | |
echo '0) khabaronline.ir' | |
echo '1) mehrnews.com' | |
sites=("https://www.khabaronline.ir/rss" "https://www.mehrnews.com/rss") | |
read site | |
reader ${sites[$site]} | |
;; | |
"Quit") | |
break | |
;; | |
*) echo "invalid option $REPLY";; | |
esac | |
done | |
} | |
if [ $# -gt 0 ];then | |
case $1 in | |
1) | |
reader | |
;; | |
2) | |
reader "https://www.khabaronline.ir/rss" w | |
;; | |
esac | |
else | |
starter | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment