Skip to content

Commit

Permalink
fix date format in filename
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimhellum committed Dec 10, 2024
1 parent 8b04994 commit 65f83b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
28 changes: 25 additions & 3 deletions dist/binance-data-downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,26 @@ now() {
date '+%Y-%m-%d %H:%M:%S.%3N'
}

#######################################
# Formats a given date string into a specified format.
# Globals:
# None
# Arguments:
# date (string): Date string
# format (string): Desired date format
# Outputs:
# Writes the formatted date to stdout
# Returns:
# 0 on success, 1 if the date is invalid
#######################################
format_date() {
local date=${1:?missing required <date> argument}
local format=${2:?missing required <format> argument}

date -d "$date" +"$format"
}


#######################################
# Converts a JSON array into newline-delimited JSON (NDJSON).
# Globals:
Expand Down Expand Up @@ -606,7 +626,7 @@ symbols() {
fail "Error: $response"?
}

echo "$response" | jq -r '.symbols[].symbol'
jq -r '.symbols[].symbol' <<< "$response"
}

#######################################
Expand Down Expand Up @@ -688,7 +708,7 @@ main() {
local product interval start_time symbols klines
local format="csv"
local output_dir="."
local end_time=$(today)
local end_time=$(now)
local max_parallel=4 num_jobs=0

while getopts ":p:i:s:e:f:o:P:h" opt; do
Expand Down Expand Up @@ -722,7 +742,9 @@ main() {

process_symbol() {
local symbol=$1
local filename="${output_dir}/${symbol}_${start_time}_${end_time}.${format}"
local start_date=$(format_date "$start_time" "%Y-%m-%d")
local end_date=$(format_date "$start_time" "%Y-%m-%d")
local filename="${output_dir}/${symbol}_${start_date}_${end_date}.${format}"
local temp_file=$(mktemp)

trap 'rm -f "$temp_file"' EXIT
Expand Down
6 changes: 4 additions & 2 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main() {
local product interval start_time symbols klines
local format="csv"
local output_dir="."
local end_time=$(today)
local end_time=$(now)
local max_parallel=4 num_jobs=0

while getopts ":p:i:s:e:f:o:P:h" opt; do
Expand Down Expand Up @@ -58,7 +58,9 @@ main() {

process_symbol() {
local symbol=$1
local filename="${output_dir}/${symbol}_${start_time}_${end_time}.${format}"
local start_date=$(format_date "$start_time" "%Y-%m-%d")
local end_date=$(format_date "$end_time" "%Y-%m-%d")
local filename="${output_dir}/${symbol}_${start_date}_${end_date}.${format}"
local temp_file=$(mktemp)

trap 'rm -f "$temp_file"' EXIT
Expand Down

0 comments on commit 65f83b7

Please sign in to comment.