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

bitcoin prices added, automation and other currencies to be added next

parent 9ae1820e
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
#!/bin/bash
# Download the HTML content
curl -s https://www.coindesk.com/price/bitcoin > bitcoin.html
# Extract the current price
price=$(grep -oP '\d{1,3}(?:,\d{3})*(?:\.\d+)? USD' bitcoin.html | head -n 1)
# Extract the 24-hour high price
high=$(grep -oP '<span class="Noto_Sans_xs_Sans-600-xs text-color-black ">\K\d{1,3}(?:,\d{3})*(?:\.\d+)? USD' bitcoin.html | head -n 1)
# Extract the 24-hour low price
low=$(grep -oP '<span class="Noto_Sans_xs_Sans-600-xs text-color-black ">\K\d{1,3}(?:,\d{3})*(?:\.\d+)? USD' bitcoin.html | tail -n 1)
# Print the extracted values for debugging
echo "The current Bitcoin price is: $price"
echo "The 24-hour high price is: $high"
echo "The 24-hour low price is: $low"
# Remove the "USD" text and commas for proper insertion into the database
price=$(echo $price | sed 's/[^0-9.]//g')
high=$(echo $high | sed 's/[^0-9.]//g')
low=$(echo $low | sed 's/[^0-9.]//g')
# Database credentials
DB_USER="root"
DB_PASS="password"
DB_NAME="bitcoin_tracker"
# Insert data into the MySQL table
mysql -u $DB_USER -p$DB_PASS $DB_NAME -e "
INSERT INTO bitcoin (price, high, low)
VALUES ($price, $high, $low);
"
echo "Data inserted: Price: $price, High: $high, Low: $low"
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