Форум сайта python.su
Добрый вечер! Подскажите ,правильно ли я вызываю функцию в планировщике?
scheduler.py:
from redis import Redis from rq_scheduler import Scheduler from datetime import datetime from task import save_exchange_rates redis_conn = Redis() scheduler = Scheduler(connection=redis_conn) scheduler.schedule( datetime.utcnow(), save_exchange_rates, interval=10, repeat=None, )
import os os.environ['DJANGO_SETTINGS_MODULE'] = 'market_capitalizations.settings' import django django.setup() import requests from exchange_rates.models import Currency def save_exchange_rates(): url = 'https://api.coinmarketcap.com/v1/ticker/' repositories = requests.get(url).json() for exchange in repositories: Currency.objects.create(name=exchange['name'], price_usd=exchange['price_usd'], last_updated=exchange['last_updated'],) if __name__ == '__main__': save_exchange_rates()
Отредактировано PavelShturm (Фев. 6, 2018 19:08:40)
Офлайн