当我尝试运行程序时,出现“ AttributeError:'BackgroundScheduler'对象没有属性'add_cron_job'” 该程序何时应正确运行。
查看文档。好像已经过时了。它正在Linux上运行。
import requests
import datetime
import time
from apscheduler.schedulers.background import BackgroundScheduler
# Provide the webhook URL that Discord generated
discord_webhook_url = 'super secrect URL'
Scheduler = Scheduler()
Scheduler.daemonic = False
Scheduler.start()
def job_function():
# Get the BTC price from CoinDesk
bitcoin_price_url = 'https://api.coindesk.com/v1/bpi/currentprice/BTC.json'
data = requests.get(bitcoin_price_url).json()
price_in_usd = data['bpi']['USD']['rate']
# Post the message to the Discord webhook
data = {
"content": "<@My Client ID> Bitcoin price is currently at $" + price_in_usd + " USD"
}
requests.post(discord_webhook_url, data=data)
Scheduler.add_cron_job(job_function, minute='0-59')
# the line above is where the error happenes.
它应该运行。并完成发布BTC价格消息不协调的功能。