-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstock1.sh
64 lines (61 loc) · 1.43 KB
/
stock1.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
if [ "$*" == "" ]; then
echo "Please enter a STOCK Ticker."
exit 1
fi
if curl -f https://www.quandl.com/api/v3/datasets/WIKI/$1.csv --output $1.csv --silent ; then
k=0
open=0
close=0
latesto=0
latestc=0
latestoamz=0
latestcamz=0
s1=0
s2=0
#read -p "Enter the stock name : " name
curl -s https://www.quandl.com/api/v3/datasets/WIKI/$1.csv --output $1.csv --silent
while IFS=, read -r f1 f2 f3 f4 f5 f6 f7
do
if (( $k != 0 ))
then
#echo "$f2"
#echo $f1 | awk -F'-' '{print $3}'
s1=`echo $s1 + $f2 | bc`
s2=`echo $s2 + $f5 | bc`
fi
(( k++ ))
done < $1.csv
#echo "$s"
open=`echo $s1 / $k | bc`
close=`echo $s2 / $k | bc`
echo "The average opening price of $1 stocks is $open."
else
echo "STOCK Ticker is Invalid"
exit 1
fi
k=0
curl -s https://www.quandl.com/api/v3/datasets/WIKI/GOOGL.csv --output GOOGL.csv --silent
while IFS=, read -r f1 f2 f3 f4 f5 f6 f7
do
if (( $k == 1 ))
then
latesto=$f2
latestc=$f5
date=$f1
fi
(( k++ ))
done < GOOGL.csv
k=0
curl -s https://www.quandl.com/api/v3/datasets/WIKI/AAPL.csv --output AAPL.csv --silent
while IFS=, read -r f1 f2 f3 f4 f5 f6 f7
do
if (( $k == 1 ))
then
latestoamz=$f2
latestcamz=$f5
dateamz=$f1
fi
(( k++ ))
done < AAPL.csv
zenity --info --text=" GOOGLE STOCK\nThe latest opening price i.e. at date $date of GOOGL stocks is $latesto\n APPLE STOCK\nThe latest opening price i.e. at date $dateamz of AAPL stocks is $latestoamz"