Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP1314 labs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iehl1g23
COMP1314 labs
Commits
484da526
Commit
484da526
authored
7 months ago
by
iehl1g23
Browse files
Options
Downloads
Patches
Plain Diff
bitcoin prices added, automation and other currencies up next
parent
e44b8839
No related branches found
No related tags found
1 merge request
!1
Master
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
bitcoin_tracker/bitcoin.html
+1
-656
1 addition, 656 deletions
bitcoin_tracker/bitcoin.html
bitcoin_tracker/collect_data.sh
+29
-10
29 additions, 10 deletions
bitcoin_tracker/collect_data.sh
with
30 additions
and
666 deletions
bitcoin_tracker/bitcoin.html
+
1
−
656
View file @
484da526
This diff is collapsed.
Click to expand it.
bitcoin_tracker/collect_data.sh
+
29
−
10
View file @
484da526
#!/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 databas
e
#
Extract the 24-hour high pric
e
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
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment