我寫了一個Python腳本來顯示桌面通知,如果比特幣的價格達到4500美元,但腳本將退出,如果價格已達到。我如何保持腳本運行?通知退出後致電
下面是代碼:
import time
import requests
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
r = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
r.json()
resp = r.json()
price = resp["bpi"]["USD"]["rate_float"]
top = 4200
if price > top :
# One time initialization of libnotify
Notify.init("Crypto Notify")
# Create the notification object
summary = "Crypto Alert!"
body = "BTC : $ %s" % (price)
notification = Notify.Notification.new(
summary,
body, # Optional
)
# Actually show on screen
notification.show()
else:
while price < top :
r =requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
print price
time.sleep(10)
移動的'while'循環。如果您希望腳本永遠運行(除非手動中斷),請將其設置爲'true:'。 – jonrsharpe
所以它會:而真: r = ... ??我希望腳本能夠永久運行並在價格達到後繼續推送通知,這有可能嗎? – Jordan