我写了一个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