-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvcure.sh
executable file
·164 lines (134 loc) · 3.04 KB
/
vcure.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
RootDir="$HOME/data"
ArchivedDir="archived"
Trash="trash"
declare -a arr=("btceur" "xrpeur" "ltceur" "etheur")
#declare -a arr=("btceur" "xrpeur")
shopt -s dotglob
###############################################################################
Collect ()
{
n=0
while [ 42 ]; do
for i in "${arr[@]}" ; do
GetData $i
sleep 1
if ! (( n % 2048)); then
Archive
fi
((n++))
done
sleep 1
done
}
GetData ()
{
cDate=`date '+%y%m%d-%H%M%S'`
mkdir -p $RootDir/$1/
echo "Current call : https://www.bitstamp.net/api/v2/ticker/$1/"
echo "Dumped to : " $RootDir/$1/$cDate.json
curl -XGET https://www.bitstamp.net/api/v2/ticker/$1/ >> $RootDir/$1/$cDate.json
echo "\r" >> $RootDir/$1/$cDate.json
}
###############################################################################
Archive ()
{
mkdir ${ArchivedDir}
for cVirtMoney in "${arr[@]}" ; do
cDir=$RootDir"/"$cVirtMoney"/"
echo "Processing "$cVirtMoney " at " $cDir
for d in $(ls -f $cVirtMoney | cut -d "-" -f1 | grep -v -E "(\.)|(\..)" | sort -u) ; do
cDay=`echo $d | cut -d "/" -f1`
cInputPath="./"$cVirtMoney"/"$d
cOutputPath="./"${ArchivedDir}"/"${cVirtMoney}"/"${cDay}"/"
mkdir -p $cOutputPath
mv -vf $cInputPath* $cOutputPath
echo " [" $cInputPath"*] files archived at " ${cOutputPath}
done
done
}
###############################################################################
CleanUp ()
{
for i in "${tmp[@]}" ; do
mv $i $Trash
done
}
ReIndex ()
{
mkdir -p "./"$Trash
for cVirtMoney in "${arr[@]}" ; do
mkdir -p "./"$cVirtMoney
done
for cVirtMoney in "${arr[@]}" ; do
n=0
for f in $(find ./$ArchivedDir -name "*.json" ); do
echo $f
mv $f $RootDir/$cVirtMoney/
tmp[$n]=$f
if ! (( n % 420)); then
CleanUp $tmp
sleep 180
fi
((n++))
done
done
}
###############################################################################
die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}
begins_with_short_option()
{
local first_option all_short_options
all_short_options='th'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
###############################################################################
print_help ()
{
printf "%s\n" "vcure v0.1 help : "
printf 'Usage: %s [option] or [-h|--help]\n' "$0"
printf "\n"
printf "\t%s\n" "-a,--archive: Archive collected data"
printf "\t%s\n" "-c,--collect: Collected the data"
printf "\t%s\n" "-r,--reindex: Force reindex archived data"
printf "\t%s\n" "-h,--help: Prints help"
printf "\n"
}
parse_commandline ()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
-a|--archive)
Archive
exit 0
;;
-c|--collect)
Collect
exit 0
;;
-r|--reindex)
ReIndex
exit 0
;;
-h|--help)
print_help
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"