diff --git a/Cryptocurrency-Prices/README.md b/Cryptocurrency-Prices/README.md new file mode 100644 index 0000000..d3a8426 --- /dev/null +++ b/Cryptocurrency-Prices/README.md @@ -0,0 +1,13 @@ +## Cryptocurrency Prices + +This programme gets the live price of cryptocurrencies. + +## Requirements + +Install the required libraries: + + $ pip install -r requirements.txt + +After that run with: + + $ python cryptocurrency-prices.py diff --git a/Cryptocurrency-Prices/cryptocurrency-prices.py b/Cryptocurrency-Prices/cryptocurrency-prices.py new file mode 100644 index 0000000..c4328b1 --- /dev/null +++ b/Cryptocurrency-Prices/cryptocurrency-prices.py @@ -0,0 +1,66 @@ +#!python3 +# -*- coding: utf-8 -*- + +import requests +from bs4 import BeautifulSoup +from colorama import init, Fore, Back, Style +import sys +import os + +#get the price +def get_price(): + #response from the url + response = requests.get(url) + + #soup object of the html content + soup = BeautifulSoup(response.content,'html.parser') + + #for bitcoin + if asset == 'btc': + price = soup.find('span',{'class':'price'}).text #bitcoin works faster with the price class + + #for other altcoins + else: + price = soup.find('span',{'class':'woobJfK-Xb2EM1W1o8yoE'}).text #other altcoins only work with this class + + return float(price.replace(",","")) + +#asset choice +asset = input('Abbreviation of the asset: ') +url = 'https://cryptowat.ch/assets/' + asset + +#catching the NoneType AttributeError error for coins that cant be found +try: + price = get_price() + +except AttributeError: + print("The asset doesn't exist or it's not supported!") + sys.exit() + +#visual +if sys.platform == 'win32': + os.system('cls') +else: + os.system('clear') + +#since the last price must be something from the start its set to 0 +price = 0 + +#loop +while True: + + #getting the price + last_price = price + price = get_price() + + #coloring the price according to the change + if price > last_price: + color = Fore.GREEN + elif last_price > price: + color = Fore.RED + else: + color = Style.RESET_ALL + + #printing the price + print('$ ',end='') + print(color + str(price) + Style.RESET_ALL) \ No newline at end of file diff --git a/Cryptocurrency-Prices/requirements.txt b/Cryptocurrency-Prices/requirements.txt new file mode 100644 index 0000000..20355cc --- /dev/null +++ b/Cryptocurrency-Prices/requirements.txt @@ -0,0 +1,3 @@ +requests +bs4 +colorama \ No newline at end of file diff --git a/README.md b/README.md index 2b45268..7dca30d 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ So far, the following projects have been integrated to this repo: |[Asymmetric Encryption](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/asymmetric_cryptography) |[victor matheus](https://github.com/victormatheusc) | |[Bitcoin price GUI](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Bitcoin-Price-GUI) |[Amirul Abu](https://github.com/amirulabu) | |[Cryptocurrency Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-converter) |[AdnCodz](https://github.com/AdnCodez) | +|[Cryptocurrency Prices](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-Prices) |[xemeds](https://github.com/xemeds) | |[Caesar Cipher](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/caeser_cipher) |[epi052](https://github.com/epi052) | |[Checksum tool](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Checksum) |[Austin Ewens](https://github.com/aewens) | |[Codechef autosubmitter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) |