-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
44 lines (32 loc) · 1.23 KB
/
main.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
import urllib.request
from threading import Timer
import winsound
import os
from datetime import datetime
coin = input('Digite o nome completo da moeda que deseja acompanhar: ')
coin = (coin.replace(" ", "-")).lower()
min = input('Digite o valor desejado para compra: ')
print('Loading...')
pastPrice = ''
def getCoinValue():
global pastPrice
page = urllib.request.urlopen('https://coinmarketcap.com/currencies/' + coin + '/')
page = str(page.read())
firstLocation = page.find('<div class="sc-16r8icm-0 kjciSH priceTitle">')
finalLocation = page.index('</div>', firstLocation)
priceLocation = page.index('$', firstLocation)
price = page[priceLocation + 1:finalLocation]
lastRefresh = datetime.now()
os.system("cls")
print('--------------------')
print((coin.replace("-", " ")).capitalize())
print('Valor desejado: $' + min)
print('Valor atual: ' + page[priceLocation:finalLocation])
print(lastRefresh.strftime("%d/%m/%Y, %H:%M:%S"))
print('--------------------')
if price.replace(",", "") <= min:
winsound.PlaySound("lightsaber.wav", winsound.SND_ASYNC)
print("COMPRA LIBERADA!")
Timer(10.0, getCoinValue).start()
pastPrice = price
Timer(1, getCoinValue).start()