File tree 4 files changed +52
-0
lines changed
WEB SCRAPING/Bitcoin Price 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -117,4 +117,5 @@ guide [HERE](https://github.com/larymak/Python-project-Scripts/blob/main/CONTRIB
117
117
| 66 | [ KeyLogger] ( https://github.com/larymak/Python-project-Scripts/tree/main/OTHERS/KeyLogger ) | [ Akhil] ( https://github.com/akhil-chagarlamudi ) |
118
118
| 67 | [ PDF Text Extractor] ( https://github.com/SamAddy/Python-project-Scripts/tree/main/PYTHON%20APPS/PDF-Text-Extractor ) | [ Samuel Addison] ( https://github.com/SamAddy )
119
119
| 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 )
120
121
Original file line number Diff line number Diff line change
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 ```
Original file line number Diff line number Diff line change
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" )
Original file line number Diff line number Diff line change
1
+ requests
You can’t perform that action at this time.
0 commit comments