-
Notifications
You must be signed in to change notification settings - Fork 10
/
update-prices.bash
executable file
·47 lines (36 loc) · 1.06 KB
/
update-prices.bash
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
#!/bin/bash
set -x
GREP_CMD="grep"
if [[ "$(uname)" == "Darwin" ]]; then
GREP_CMD="ggrep"
fi
result_file="./result.tmp"
now="$(date -Iseconds)"
pnpm run start > "$result_file"
epoch=$($GREP_CMD -oP "^epoch \K[0-9.]*" "$result_file")
if [[ -z $epoch ]]
then
echo "Epoch not found in the result file!"
exit 1
fi
# Define a regex pattern to match the "epoch" line
EPOCH_PATTERN="^epoch [0-9]+$"
# Set the flag to start processing lines after the epoch line is found
START_PROCESSING=false
# Read the input file line by line
while IFS= read -r line; do
if [[ $line =~ $EPOCH_PATTERN ]]; then
START_PROCESSING=true
continue
fi
if $START_PROCESSING; then
pool=$(echo $line | awk '{print $1}')
price=$(echo $line | awk '{$1=""; print $0}' | sed 's/^ *//; s/ *$//')
if [ ! -f "./db/${pool}.csv" ]; then
echo "timestamp,epoch,price" > "./db/${pool}.csv"
fi
echo "$now,$epoch,$price" >> "./db/${pool}.csv"
echo "Updated or created file: ${pool}.csv with content: $price"
fi
done < "$result_file"
rm "$result_file"