Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Data Management Coursework 2
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iehl1g23
Data Management Coursework 2
Commits
b3016119
Commit
b3016119
authored
3 months ago
by
iehl1g23
Browse files
Options
Downloads
Patches
Plain Diff
bitcoin prices added, automation and other currencies to be added next
parent
9ae1820e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bitcoin.html
+1
-0
1 addition, 0 deletions
bitcoin.html
collect_data.sh
+36
-0
36 additions, 0 deletions
collect_data.sh
with
37 additions
and
0 deletions
bitcoin.html
0 → 100644
+
1
−
0
View file @
b3016119
This diff is collapsed.
Click to expand it.
collect_data.sh
0 → 100755
+
36
−
0
View file @
b3016119
#!/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
"
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