mirror of
https://github.com/Llewellynvdm/CoinRate.git
synced 2024-11-21 10:45:08 +00:00
Added SMS option, fixed some typos, and bugs
This commit is contained in:
parent
f41f52f2ab
commit
a00a960c34
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
repos
|
||||
exclude
|
||||
notify
|
||||
github
|
||||
sms
|
||||
smsto
|
34
getPrice.sh
34
getPrice.sh
@ -23,6 +23,9 @@ VDMHOME=~/
|
||||
# load notify
|
||||
. "$DIR/notify.sh"
|
||||
|
||||
# load sms
|
||||
. "$DIR/sms.sh"
|
||||
|
||||
# main function
|
||||
function main () {
|
||||
echoTweak "Getting the current price of $Currency in $Target"
|
||||
@ -48,6 +51,8 @@ function main () {
|
||||
fi
|
||||
# show linux messages if any were loaded
|
||||
showLinuxMessage
|
||||
# send SMS messages if any were loaded
|
||||
sendSMSMessage
|
||||
}
|
||||
|
||||
function getTarget() {
|
||||
@ -136,6 +141,8 @@ function sendMessage () {
|
||||
sendTelegram "$message"
|
||||
# set Linux messages
|
||||
setLinuxMessage "$message"
|
||||
# set SMS messages
|
||||
setSMSMessage "$message"
|
||||
}
|
||||
|
||||
# check if we already showed the message today
|
||||
@ -202,6 +209,8 @@ AboveValue=0
|
||||
Telegram=0
|
||||
linuxMessages=()
|
||||
LinuxNotice=0
|
||||
SMSMessages=()
|
||||
SMS=0
|
||||
API="https://cex.io/api/last_price/"
|
||||
VDMHOME=~/
|
||||
|
||||
@ -229,6 +238,7 @@ Getting Coin Value in Fiat Currency at set price
|
||||
-b Send Notice below target value once a day
|
||||
-a Send Notice above target value once a day (default)
|
||||
-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)
|
||||
|
||||
EOF
|
||||
@ -240,7 +250,7 @@ exit 1
|
||||
# http://mywiki.wooledge.org/BashFAQ/035
|
||||
# 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
|
||||
c)
|
||||
Currency=$OPTARG
|
||||
@ -269,6 +279,9 @@ while getopts ":c:t:s:v:A:B:b :a :n :l :" opt; do
|
||||
n)
|
||||
Telegram=1
|
||||
;;
|
||||
m)
|
||||
SMS=1
|
||||
;;
|
||||
l)
|
||||
LinuxNotice=1
|
||||
;;
|
||||
@ -319,6 +332,25 @@ function showLinuxMessage () {
|
||||
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
|
||||
function sendTelegram () {
|
||||
# check if we should send telegram
|
||||
|
17
notify.sh
17
notify.sh
@ -21,14 +21,21 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# Telegram notify
|
||||
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
|
||||
NOTIFY=$(head -n 1 "$DIR/notify")
|
||||
local NOTIFY=$(head -n 1 "$DIR/notify")
|
||||
# get the keys
|
||||
keys=( $NOTIFY )
|
||||
IFS=$' '
|
||||
local keys=( $NOTIFY )
|
||||
# set chatid & token
|
||||
chatid="${keys[0]}"
|
||||
token="${keys[1]}"
|
||||
default_message="notify!"
|
||||
local chatid="${keys[0]}"
|
||||
local token="${keys[1]}"
|
||||
local default_message="notify!"
|
||||
|
||||
if [ -z "$@" ]
|
||||
then
|
||||
|
50
sms.sh
Normal file
50
sms.sh
Normal 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
3
sms.txt
Normal 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 ;)
|
Loading…
Reference in New Issue
Block a user