Skip to content
Snippets Groups Projects
Commit 539a904c authored by iehl1g23's avatar iehl1g23
Browse files

graph renamed to btc_graph and changed code to match new database and table name

parent 3ffe3763
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# Database credentials
DB_USER="root"
DB_PASS="password"
DB_NAME="crypto_tracker"
# Get today's date in YYYY-MM-DD format
today=$(date +'%Y-%m-%d')
# Temporary file for storing the data
temp_file="temp_data.txt"
# Query to get the timestamp and price for today
mysql -u "$DB_USER" -p"$DB_PASS" -D "$DB_NAME" -e "SELECT UNIX_TIMESTAMP(timestamp), price FROM btc_prices WHERE DATE(timestamp) = '$today' ORDER BY timestamp" > "$temp_file"
# Format the data for gnuplot (remove the first line containing column names)
tail -n +2 "$temp_file" > "formatted_data.txt"
# Resample the data to get one data point every 2.4 hours (8640 seconds)
awk 'BEGIN {last_timestamp = 0} {if ($1 - last_timestamp >= 8640) {print $1, $2; last_timestamp = $1}}' formatted_data.txt > "resampled_data.txt"
# Create plots using gnuplot
gnuplot << EOF
set terminal pngcairo size 800,600 enhanced font 'Arial,10'
set output 'price_$today.png'
set title 'Bitcoin Price vs Time ($today)'
set xlabel 'Time'
set ylabel 'Price (USD)'
# Set the time format for the x-axis
set timefmt "%s" # Input format is Unix timestamp
set xdata time # Use time for the x-axis
set format x "%H:%M" # Format x axis as hour:minute
# Use the formatted data
plot 'formatted_data.txt' using 1:2 with linespoints title 'Price'
EOF
# Clean up temporary files
rm "$temp_file" "formatted_data.txt" "resampled_data.txt"
echo "Price graph for today generated successfully!"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment