mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added Cryptocurrency prices (#223)
* Added Cryptocurrency prices * Update README.md
This commit is contained in:
parent
2eb833db84
commit
cdaa837fe4
13
Cryptocurrency-Prices/README.md
Normal file
13
Cryptocurrency-Prices/README.md
Normal file
|
@ -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
|
66
Cryptocurrency-Prices/cryptocurrency-prices.py
Normal file
66
Cryptocurrency-Prices/cryptocurrency-prices.py
Normal file
|
@ -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)
|
3
Cryptocurrency-Prices/requirements.txt
Normal file
3
Cryptocurrency-Prices/requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
requests
|
||||||
|
bs4
|
||||||
|
colorama
|
|
@ -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) |
|
|[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) |
|
|[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 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) |
|
|[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) |
|
|[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) |
|
|[Codechef autosubmitter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) |
|
||||||
|
|
Loading…
Reference in New Issue
Block a user