Skip to content

Commit 67b5468

Browse files
committed
New Project: Bitcoin Price
1 parent 5f99866 commit 67b5468

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,5 @@ guide [HERE](https://github.com/larymak/Python-project-Scripts/blob/main/CONTRIB
117117
| 66 | [KeyLogger](https://github.com/larymak/Python-project-Scripts/tree/main/OTHERS/KeyLogger) | [Akhil](https://github.com/akhil-chagarlamudi) |
118118
| 67 | [PDF Text Extractor](https://github.com/SamAddy/Python-project-Scripts/tree/main/PYTHON%20APPS/PDF-Text-Extractor) | [Samuel Addison](https://github.com/SamAddy)
119119
| 68 | [Analyze docx file](https://github.com/larymak/Python-project-Scripts/tree/main/AUTOMATION/analyzing%20and%20writing%20.docx%20file) | [Kashaan Mahmood](https://github.com/Kashaan-M)
120+
| 69 | [Bitcoin Price](https://github.com/larymak/Python-project-Scripts/tree/main/WEB%20SCRAPING/Bitcoin%20Price) | [Olu-Olagbuji Delight](https://github.com/Dheelyte)
120121

WEB SCRAPING/Bitcoin Price/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Bitcoin Price
2+
3+
## Desciption
4+
This script is used to get the current price of Bitcoin in U.S. Dollars
5+
6+
<br>
7+
8+
## Installation
9+
10+
Install request with the following command or using the requirements.txt file:
11+
12+
```pip install requests```
13+
14+
<br>
15+
16+
## Usage
17+
Input the number of bitcoins as command line argument
18+
19+
```python bitcoin.py 1```
20+
21+
<br>
22+
23+
```python bitcoin.py 5```

WEB SCRAPING/Bitcoin Price/bitcoin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import requests
2+
import sys
3+
4+
5+
""" Exit program if no command-line argument is provided """
6+
if len(sys.argv) == 1:
7+
sys.exit("Missing command-line argument")
8+
9+
10+
"""
11+
Convert command-line argument to float or
12+
Exit if command line argument is not a number
13+
"""
14+
try:
15+
bitcoin = sys.argv[1]
16+
bitcoin = float(bitcoin)
17+
except ValueError:
18+
sys.exit("Command-line argument is not a number")
19+
20+
21+
"""Get Bitcoin price"""
22+
try:
23+
response = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
24+
rate = response.json()["bpi"]["USD"]["rate_float"]
25+
print(f"Current Price: ${bitcoin * rate:,.4f}")
26+
except requests.RequestException:
27+
print("An Error Occurred")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

0 commit comments

Comments
 (0)