modified to for multi user tracking
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.csv
|
||||||
|
*.png
|
||||||
@@ -1,80 +1,76 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Define input CSV file and temporary file for formatted data
|
# Source the configuration file
|
||||||
input_file="assets_data.csv"
|
source ./user_ids.conf
|
||||||
temp_file="total_asset_data_for_plot.txt"
|
|
||||||
temp_file2="cash_data_for_plot.txt"
|
|
||||||
output_png="total_assets.png"
|
|
||||||
output_png2="diamonds_on_hand.png"
|
|
||||||
|
|
||||||
|
# Directory where CSV files are stored
|
||||||
|
INPUT_DIR="/home/eric/asset_tracker"
|
||||||
|
|
||||||
|
# Create output directory for charts if it doesn't exist
|
||||||
|
#OUTPUT_DIR="/var/www/taylors/img/silver-dragon"
|
||||||
|
OUTPUT_DIR="/home/eric/asset_tracker"
|
||||||
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Process each user ID
|
||||||
|
for USER_ID in "${USER_IDS[@]}"; do
|
||||||
|
# Define input CSV file and temporary files for formatted data for this user
|
||||||
|
input_file="${INPUT_DIR}/assets_data_${USER_ID}.csv"
|
||||||
|
|
||||||
|
# Skip if the user's CSV file doesn't exist
|
||||||
|
if [ ! -f "$input_file" ]; then
|
||||||
|
echo "Warning: CSV file for user $USER_ID not found. Skipping..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
temp_total_assets="${INPUT_DIR}/total_asset_data_for_plot_${USER_ID}.txt"
|
||||||
|
temp_diamonds_on_hand="${INPUT_DIR}/cash_data_for_plot_${USER_ID}.txt"
|
||||||
|
png_total_assets="${OUTPUT_DIR}/total_assets_${USER_ID}.png"
|
||||||
|
png_diamonds_on_hand="${OUTPUT_DIR}/diamonds_on_hand_${USER_ID}.png"
|
||||||
|
|
||||||
# Extract date (without time) and total_assets columns for gnuplot
|
# Extract date (without time) and total_assets columns for gnuplot
|
||||||
awk -F, 'NR > 1 { print substr($1, 1, 10), $4 }' "$input_file" > "$temp_file"
|
awk -F, 'NR > 1 { print substr($1, 1, 10), $4 }' "$input_file" > "$temp_total_assets"
|
||||||
|
|
||||||
# Extract date (without time) and diamonds columns for gnuplot
|
# Extract date (without time) and diamonds columns for gnuplot
|
||||||
awk -F, 'NR > 1 { print substr($1, 1, 10), $3 }' "$input_file" > "$temp_file2"
|
awk -F, 'NR > 1 { print substr($1, 1, 10), $3 }' "$input_file" > "$temp_diamonds_on_hand"
|
||||||
|
|
||||||
# Debugging Step: Print the first few lines of the temporary file to verify the output
|
# Plot with gnuplot in ASCII mode (for debugging)
|
||||||
# echo "Sample data from $temp_file2:"
|
echo "Generating charts for user ID: $USER_ID"
|
||||||
# head -n 5 "$temp_file2"
|
|
||||||
|
|
||||||
# Plot with gnuplot in ASCII mode
|
# Plot total assets chart
|
||||||
gnuplot <<- EOF
|
gnuplot <<- EOF
|
||||||
set datafile separator " "
|
set datafile separator " "
|
||||||
set xdata time
|
set xdata time
|
||||||
set timefmt "%Y-%m-%d"
|
set timefmt "%Y-%m-%d"
|
||||||
set format x "%m-%d" # Display only month and day on x-axis
|
set format x "%m-%d" # Display only month and day on x-axis
|
||||||
set format y "%.0f" # Display y-axis as plain numbers, no scientific notation
|
set format y "%.0f" # Display y-axis as plain numbers, no scientific notation
|
||||||
set title "Total Assets Over Time"
|
set title "Total Assets Over Time for User $USER_ID"
|
||||||
set xlabel "Date"
|
set xlabel "Date"
|
||||||
set ylabel "Total Assets"
|
set ylabel "Total Assets"
|
||||||
set grid
|
set grid
|
||||||
set terminal dumb size 80,20 # ASCII output, size 80x20
|
set terminal dumb size 80,20 # ASCII output, size 80x20
|
||||||
set autoscale xfixmin
|
set autoscale xfixmin
|
||||||
set autoscale xfixmax
|
set autoscale xfixmax
|
||||||
plot "$temp_file" using 1:2 with lines notitle
|
plot "$temp_total_assets" using 1:2 with lines notitle
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Plot with gnuplot in ASCII mode
|
# Plot diamonds chart
|
||||||
gnuplot <<- EOF
|
gnuplot <<- EOF
|
||||||
set datafile separator " "
|
set datafile separator " "
|
||||||
set xdata time
|
set xdata time
|
||||||
set timefmt "%Y-%m-%d"
|
set timefmt "%Y-%m-%d"
|
||||||
set format x "%m-%d" # Display only month and day on x-axis
|
set format x "%m-%d" # Display only month and day on x-axis
|
||||||
set format y "%.0f" # Display y-axis as plain numbers, no scientific notation
|
set format y "%.0f" # Display y-axis as plain numbers, no scientific notation
|
||||||
set title "On Hand Diamonds Over Time"
|
set title "On Hand Diamonds Over Time for User $USER_ID"
|
||||||
set xlabel "Date"
|
set xlabel "Date"
|
||||||
set ylabel "Diamonds"
|
set ylabel "Diamonds"
|
||||||
set grid
|
set grid
|
||||||
set terminal dumb size 80,20 # ASCII output, size 80x20
|
set terminal dumb size 80,20 # ASCII output, size 80x20
|
||||||
set autoscale xfixmin
|
set autoscale xfixmin
|
||||||
set autoscale xfixmax
|
set autoscale xfixmax
|
||||||
plot "$temp_file2" using 1:2 with lines notitle
|
plot "$temp_diamonds_on_hand" using 1:2 with lines notitle
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Plot with gnuplot in PNG format (black background, white text, orange plot line)
|
# Plot with gnuplot in PNG format (black background, white text, orange plot line)
|
||||||
#gnuplot <<- EOF
|
|
||||||
# set datafile separator " "
|
|
||||||
# set xdata time
|
|
||||||
# set timefmt "%Y-%m-%d"
|
|
||||||
# set format x "%m-%d" # Display only month and day on x-axis
|
|
||||||
# set format y "%.0f" # Display y-axis as plain numbers, no scientific notation
|
|
||||||
# set title "Total Assets Over Time" font ",14" textcolor rgb "#FFFFFF"
|
|
||||||
# set xlabel "Date" font ",12" textcolor rgb "#FFFFFF" #white
|
|
||||||
# set ylabel "Total Assets" font ",12" textcolor rgb "#FFFFFF" #white
|
|
||||||
# set grid linecolor rgb "#FFFFFF" # White grid lines
|
|
||||||
# set xtics textcolor rgb "#FFFFFF" # White x-axis labels
|
|
||||||
# set ytics textcolor rgb "#FFFFFF" # White y-axis labels
|
|
||||||
# set border linecolor rgb "#FFFFFF" # White border
|
|
||||||
# set terminal pngcairo size 800,600 enhanced font 'Arial,10' background rgb "black" # PNG output with black background
|
|
||||||
# set output "$output_png"
|
|
||||||
# set style line 1 linecolor rgb "#FE6A00" linetype 1 linewidth 2 # Orange plot curve (#FE6A00)
|
|
||||||
# set autoscale xfixmin
|
|
||||||
# set autoscale xfixmax
|
|
||||||
# plot "$temp_file" using 1:2 with lines ls 1
|
|
||||||
#EOF
|
|
||||||
|
|
||||||
# Plot with gnuplot in PNG format (transparent background, white text, orange plot line)
|
|
||||||
gnuplot <<- EOF
|
gnuplot <<- EOF
|
||||||
set datafile separator " "
|
set datafile separator " "
|
||||||
set xdata time
|
set xdata time
|
||||||
@@ -89,14 +85,14 @@ gnuplot <<- EOF
|
|||||||
set ytics textcolor rgb "#FFFFFF" # White y-axis labels
|
set ytics textcolor rgb "#FFFFFF" # White y-axis labels
|
||||||
set border linecolor rgb "#FFFFFF" # White border
|
set border linecolor rgb "#FFFFFF" # White border
|
||||||
set terminal pngcairo size 400,300 enhanced font 'Arial,10' background rgb "black" # BLACK background
|
set terminal pngcairo size 400,300 enhanced font 'Arial,10' background rgb "black" # BLACK background
|
||||||
set output "$output_png"
|
set output "$png_total_assets"
|
||||||
set style line 1 linecolor rgb "#FE6A00" linetype 1 linewidth 2 # Orange plot curve (#FE6A00)
|
set style line 1 linecolor rgb "#FE6A00" linetype 1 linewidth 2 # Orange plot curve (#FE6A00)
|
||||||
set autoscale xfixmin
|
set autoscale xfixmin
|
||||||
set autoscale xfixmax
|
set autoscale xfixmax
|
||||||
plot "$temp_file" using 1:2 with lines notitle ls 1
|
plot "$temp_total_assets" using 1:2 with lines notitle ls 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Plot diamonds chart in PNG format
|
||||||
gnuplot <<- EOF
|
gnuplot <<- EOF
|
||||||
set datafile separator " "
|
set datafile separator " "
|
||||||
set xdata time
|
set xdata time
|
||||||
@@ -111,16 +107,38 @@ gnuplot <<- EOF
|
|||||||
set ytics textcolor rgb "#FFFFFF" # White y-axis labels
|
set ytics textcolor rgb "#FFFFFF" # White y-axis labels
|
||||||
set border linecolor rgb "#FFFFFF" # White border
|
set border linecolor rgb "#FFFFFF" # White border
|
||||||
set terminal pngcairo size 400,300 enhanced font 'Arial,10' background rgb "black" # BLACK background
|
set terminal pngcairo size 400,300 enhanced font 'Arial,10' background rgb "black" # BLACK background
|
||||||
set output "$output_png2"
|
set output "$png_diamonds_on_hand"
|
||||||
set style line 1 linecolor rgb "#2CB9CF" linetype 1 linewidth 2 # teal plot curve
|
set style line 1 linecolor rgb "#2CB9CF" linetype 1 linewidth 2 # teal plot curve
|
||||||
set autoscale xfixmin
|
set autoscale xfixmin
|
||||||
set autoscale xfixmax
|
set autoscale xfixmax
|
||||||
plot "$temp_file2" using 1:2 with lines notitle ls 1
|
plot "$temp_diamonds_on_hand" using 1:2 with lines notitle ls 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Copy the generated PNG file to the webserver via SSH
|
# Clean up temporary files
|
||||||
scp "$output_png" "$output_png2" root@taylors.life:/var/www/taylors/img/silver-dragon/
|
rm -f "$temp_total_assets"
|
||||||
|
rm -f "$temp_diamonds_on_hand"
|
||||||
|
|
||||||
# Clean up temporary file
|
echo "Charts generated for user ID: $USER_ID"
|
||||||
rm "$temp_file"
|
done
|
||||||
rm "$temp_file2"
|
|
||||||
|
# Copy the generated PNG files to the webserver via SSH
|
||||||
|
echo "Copying charts to web server..."
|
||||||
|
|
||||||
|
# Change to output directory
|
||||||
|
cd "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Get list of files matching patterns
|
||||||
|
total_files=$(ls total_assets_*.png 2>/dev/null)
|
||||||
|
diamonds_files=$(ls diamonds_on_hand_*.png 2>/dev/null)
|
||||||
|
|
||||||
|
# Copy total assets files if they exist
|
||||||
|
if [ -n "$total_files" ]; then
|
||||||
|
scp $total_files root@taylors.life:/var/www/erictaylor/img/asset_tracker/
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy diamonds files if they exist
|
||||||
|
if [ -n "$diamonds_files" ]; then
|
||||||
|
scp $diamonds_files root@taylors.life:/var/www/erictaylor/img/asset_tracker/
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All charts processed and copied."
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# User ID (can be changed easily)
|
# Source the configuration file
|
||||||
USER_ID="667"
|
source ./user_ids.conf
|
||||||
|
|
||||||
# URL of the webpage to extract the data from
|
# URL template for the webpage to extract the data from
|
||||||
URL="https://www.prismatic-imperium.com/user_page.php?user=$USER_ID"
|
URL_TEMPLATE="https://www.prismatic-imperium.com/user_page.php?user="
|
||||||
|
|
||||||
# CSV file to store the extracted data
|
# Directory where CSV files will be stored
|
||||||
CSV_FILE="/home/eric/assets_data.csv"
|
OUTPUT_DIR="/home/eric/asset_tracker"
|
||||||
|
|
||||||
|
# Create output directory if it doesn't exist
|
||||||
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Function to process a single user ID
|
||||||
|
process_user() {
|
||||||
|
local USER_ID="$1"
|
||||||
|
local URL="${URL_TEMPLATE}${USER_ID}"
|
||||||
|
local CSV_FILE="${OUTPUT_DIR}/assets_data_${USER_ID}.csv"
|
||||||
|
|
||||||
# Check if the CSV file exists, if not, create it with headers
|
# Check if the CSV file exists, if not, create it with headers
|
||||||
if [ ! -f "$CSV_FILE" ]; then
|
if [ ! -f "$CSV_FILE" ]; then
|
||||||
@@ -35,5 +44,14 @@ if [ ${#value_array[@]} -eq 3 ]; then
|
|||||||
echo "$current_datetime,$user_rank,$liquid_assets,$total_assets" >> "$CSV_FILE"
|
echo "$current_datetime,$user_rank,$liquid_assets,$total_assets" >> "$CSV_FILE"
|
||||||
else
|
else
|
||||||
# Error handling: print a message if values were not extracted properly
|
# Error handling: print a message if values were not extracted properly
|
||||||
echo "Error: Could not extract all values or incorrect number of values." >&2
|
echo "Error: Could not extract all values or incorrect number of values for user $USER_ID." >&2
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process each user ID in the array
|
||||||
|
for USER_ID in "${USER_IDS[@]}"; do
|
||||||
|
echo "Processing user ID: $USER_ID"
|
||||||
|
process_user "$USER_ID"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "All users processed."
|
||||||
|
|||||||
3
snippet.md
Normal file
3
snippet.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|

|
||||||
|

|
||||||
3
user_ids.conf
Executable file
3
user_ids.conf
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# User IDs configuration file
|
||||||
|
USER_IDS=("667" "31" "744")
|
||||||
Reference in New Issue
Block a user