Inital commit

This commit is contained in:
Eric Taylor
2025-09-30 09:48:55 -04:00
commit 8c0406d5d7
2 changed files with 165 additions and 0 deletions

39
extract_assets.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
# User ID (can be changed easily)
USER_ID="667"
# URL of the webpage to extract the data from
URL="https://www.prismatic-imperium.com/user_page.php?user=$USER_ID"
# CSV file to store the extracted data
CSV_FILE="/home/eric/assets_data.csv"
# Check if the CSV file exists, if not, create it with headers
if [ ! -f "$CSV_FILE" ]; then
echo "CSV file does not exist. Creating it with headers."
echo "date,rank,diamonds,total_assets" > "$CSV_FILE"
fi
# Fetch the webpage content and extract all the values within the user_assets_number span
values=$(curl -s "$URL" | grep -oP '(?<=<span class="user_assets_number">)[^<]+')
# Convert values to an array (this splits the values by newline)
IFS=$'\n' read -r -d '' -a value_array <<< "$values"
# Remove commas from each value
user_rank=$(echo "${value_array[0]}" | tr -d ',')
liquid_assets=$(echo "${value_array[1]}" | tr -d ',')
total_assets=$(echo "${value_array[2]}" | tr -d ',')
# Get the current date and time
current_datetime=$(date "+%Y-%m-%d %H:%M:%S")
# Check if we have exactly 3 values (rank, diamonds, total_assets)
if [ ${#value_array[@]} -eq 3 ]; then
# Append the values to the CSV file
echo "$current_datetime,$user_rank,$liquid_assets,$total_assets" >> "$CSV_FILE"
else
# Error handling: print a message if values were not extracted properly
echo "Error: Could not extract all values or incorrect number of values." >&2
fi