我有這個方法:def getExchangeRates(): """ Here we have the function that will retrieve the latest rates from fixer.io """ rates = {} response = urlopen('http://data.fixer.io/api/latest?access_key=c2f5070ad78b0748111281f6475c0bdd') data = response.read() rdata = json.loads(data.decode(), parse_float=float) rates_from_rdata = rdata.get('rates', {}) for rate_symbol in ['USD', 'GBP', 'HKD', 'AUD', 'JPY', 'SEK', 'NOK']: try: rates[rate_symbol] = rates_from_rdata[rate_symbol] except KeyError: logging.warning('rate for {} not found in rdata'.format(rate_symbol)) pass return rates@require_http_methods(['GET', 'POST'])def index(request): rates = getExchangeRates() fixerio_rates = [Fixerio_rates(currency=currency, rate=rate) for currency, rate in rates.items()] Fixerio_rates.objects.bulk_create(fixerio_rates) return render(request, 'index.html') 我想安排這個,比方說,每天早上 9 點,周末除外。我還沒有找到一些關(guān)于如何基于這樣一個特定的日期時間來安排這個的綜合教程,而且,我不知道我是否可以安排這個方法,或者在我的tasks文件中創(chuàng)建另一個繼承這個方法的方法,并在任何時間運(yùn)行具體日期。我的celery.py項目根目錄中有該tasks.py文件,我的應(yīng)用程序文件夾中有該文件。或者,也許芹菜不是解決這種情況的方法?有任何想法嗎?
添加回答
舉報
0/150
提交
取消