-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathupdate-prices.bash
More file actions
executable file
·42 lines (32 loc) · 1009 Bytes
/
update-prices.bash
File metadata and controls
executable file
·42 lines (32 loc) · 1009 Bytes
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
#!/bin/bash
set -x
result_file="./result.tmp"
now="$(date -Iseconds)"
pnpm run start > "$result_file"
epoch=$(awk '/^epoch [0-9]+$/ {print $2}' "$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"