1
0
mirror of https://github.com/Llewellynvdm/CoinRate.git synced 2024-11-24 19:37:32 +00:00

Added SMS option, fixed some typos, and bugs

This commit is contained in:
Llewellyn van der Merwe 2017-12-27 16:55:23 +02:00
parent f41f52f2ab
commit a00a960c34
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
6 changed files with 103 additions and 9 deletions

5
.gitignore vendored
View File

@ -1,4 +1,3 @@
repos
exclude
notify notify
github sms
smsto

View File

@ -23,6 +23,9 @@ VDMHOME=~/
# load notify # load notify
. "$DIR/notify.sh" . "$DIR/notify.sh"
# load sms
. "$DIR/sms.sh"
# main function # main function
function main () { function main () {
echoTweak "Getting the current price of $Currency in $Target" echoTweak "Getting the current price of $Currency in $Target"
@ -48,6 +51,8 @@ function main () {
fi fi
# show linux messages if any were loaded # show linux messages if any were loaded
showLinuxMessage showLinuxMessage
# send SMS messages if any were loaded
sendSMSMessage
} }
function getTarget() { function getTarget() {
@ -136,6 +141,8 @@ function sendMessage () {
sendTelegram "$message" sendTelegram "$message"
# set Linux messages # set Linux messages
setLinuxMessage "$message" setLinuxMessage "$message"
# set SMS messages
setSMSMessage "$message"
} }
# check if we already showed the message today # check if we already showed the message today
@ -202,6 +209,8 @@ AboveValue=0
Telegram=0 Telegram=0
linuxMessages=() linuxMessages=()
LinuxNotice=0 LinuxNotice=0
SMSMessages=()
SMS=0
API="https://cex.io/api/last_price/" API="https://cex.io/api/last_price/"
VDMHOME=~/ VDMHOME=~/
@ -229,6 +238,7 @@ Getting Coin Value in Fiat Currency at set price
-b Send Notice below target value once a day -b Send Notice below target value once a day
-a Send Notice above target value once a day (default) -a Send Notice above target value once a day (default)
-n Send A Telegram Notice aswell (always shows comandline Notice) -n Send A Telegram Notice aswell (always shows comandline Notice)
-m Send A SMS Notice aswell (always shows comandline Notice)
-l Show A Linux Notice aswell (always shows comandline Notice) -l Show A Linux Notice aswell (always shows comandline Notice)
EOF EOF
@ -240,7 +250,7 @@ exit 1
# http://mywiki.wooledge.org/BashFAQ/035 # http://mywiki.wooledge.org/BashFAQ/035
# http://wiki.bash-hackers.org/howto/getopts_tutorial # http://wiki.bash-hackers.org/howto/getopts_tutorial
while getopts ":c:t:s:v:A:B:b :a :n :l :" opt; do while getopts ":c:t:s:v:A:B:b :a :n :m :l :" opt; do
case $opt in case $opt in
c) c)
Currency=$OPTARG Currency=$OPTARG
@ -269,6 +279,9 @@ while getopts ":c:t:s:v:A:B:b :a :n :l :" opt; do
n) n)
Telegram=1 Telegram=1
;; ;;
m)
SMS=1
;;
l) l)
LinuxNotice=1 LinuxNotice=1
;; ;;
@ -319,6 +332,25 @@ function showLinuxMessage () {
fi fi
} }
# set sms messages
function setSMSMessage () {
# check if we should send sms messages
if (( "$SMS" == 1 && "$show" == 1 ));
then
SMSMessages+=("$1")
fi
}
# send sms messages
function sendSMSMessage () {
# check if we have messages to send
if [ ${#SMSMessages[@]} -gt 0 ]; then
IFS=$'\n'
messages="${SMSMessages[*]}"
smsMe "${messages}"
fi
}
# send Telegram # send Telegram
function sendTelegram () { function sendTelegram () {
# check if we should send telegram # check if we should send telegram

View File

@ -21,14 +21,21 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Telegram notify # Telegram notify
function notifyMe() { function notifyMe() {
# check if notify is set
if [ ! -f "$DIR/notify" ]
then
echo "Please set the details for Telegram found in notify.txt"
exit 1
fi
# get first line # get first line
NOTIFY=$(head -n 1 "$DIR/notify") local NOTIFY=$(head -n 1 "$DIR/notify")
# get the keys # get the keys
keys=( $NOTIFY ) IFS=$' '
local keys=( $NOTIFY )
# set chatid & token # set chatid & token
chatid="${keys[0]}" local chatid="${keys[0]}"
token="${keys[1]}" local token="${keys[1]}"
default_message="notify!" local default_message="notify!"
if [ -z "$@" ] if [ -z "$@" ]
then then

50
sms.sh Normal file
View File

@ -0,0 +1,50 @@
#!/bin/bash
#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
# __ __ _ _____ _ _ __ __ _ _ _
# \ \ / / | | | __ \ | | | | | \/ | | | | | | |
# \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
# \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
# \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
# \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
# | |
# |_|
#/-------------------------------------------------------------------------------------------------------------------------------/
#
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
# @copyright Copyright (C) 2016. All Rights Reserved
# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
#
#/-----------------------------------------------------------------------------------------------------------------------------/
# get script path
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# clickatell sms HTTP
function smsMe() {
# check if sms details are set
if [ ! -f "$DIR/sms" ]
then
echo "Please set the details for clickatell found in sms.txt"
exit 1
fi
# check if phone numbers are set
if [ ! -f "$DIR/smsto" ]
then
echo "Please set the phone numbers as found in smsto.txt"
exit 1
fi
# set Args
local message="$1"
# get first line
local SMSd=$(head -n 1 "$DIR/sms")
local to=$(head -n 1 "$DIR/smsto")
# get the keys
IFS=$' '
local keyss=( $SMSd )
# set user, password & api_id
local username="${keyss[0]}"
local password="${keyss[1]}"
local api_id="${keyss[2]}"
# send the sms's
curl -s --data "user=${username}&password=${password}&api_id=${api_id}&to=${to}&text=${message}" "https://api.clickatell.com/http/sendmsg"
}

3
sms.txt Normal file
View File

@ -0,0 +1,3 @@
# here you add the sms username, password and API id (example)
# username password api_id
# James xxxxxx 0000001 (remove this note and remove .txt from the file name ;)

3
smsto.txt Normal file
View File

@ -0,0 +1,3 @@
# here you add all then numbers to sms comma separated(example)
# number,number,number
# 264810000000,264811111111,264812222222,264812222222 (remove this note and remove .txt from the file name ;)