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

bitcoin prices added, automation and other currencies up next

parent e44b8839
No related branches found
No related tags found
1 merge request!1Master
This diff is collapsed.
#!/bin/bash #!/bin/bash
# Fetch Bitcoin price data # Download the HTML content
curl -s https://coinmarketcap.com/currencies/bitcoin/ > bitcoin.html curl -s https://www.coindesk.com/price/bitcoin > bitcoin.html
# Parse data # Extract the current price
price=$(grep -oP '"priceValue":\s*"\K[0-9.,]+' bitcoin.html | head -1) price=$(grep -oP '\d{1,3}(?:,\d{3})*(?:\.\d+)? USD' bitcoin.html | head -n 1)
high=$(grep -oP '"highValue":\s*"\K[0-9.,]+' bitcoin.html | head -1)
low=$(grep -oP '"lowValue":\s*"\K[0-9.,]+' bitcoin.html | head -1)
# Insert into MySQL database # Extract the 24-hour high price
mysql -u root -e "USE bitcoin_tracker; INSERT INTO prices (price, high, low) VALUES ('$price', '$high', '$low');" 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)
# Output for verification # Extract the 24-hour low price
echo "Price: $price, High: $high, Low: $low" 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.
Please register or to comment