-
Notifications
You must be signed in to change notification settings - Fork 6
/
adasda.py
71 lines (53 loc) · 1.39 KB
/
adasda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!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':
# bitcoin works faster with the price class
price = soup.find('span', {'class': 'price'}).text
#for other altcoins
else:
# other altcoins only work with this class
price = soup.find('span', {'class': 'woobJfK-Xb2EM1W1o8yoE'}).text
return float(price)
#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)