moneropro/app/charts/management/commands/initialize_data.py
Kumi 8c779ba5e5
Some checks are pending
Docker / build (push) Waiting to run
feat(management): add command to initialize chart data
Introduced a new management command to initialize the database with current data for specified cryptocurrencies (`xmr`, `btc`, `dash`, `zec`, `grin`). This process involves deleting existing data entries and fetching updated historical and market data. This enhancement ensures the application starts with the most recent information, improving data accuracy and reliability.
2024-11-13 14:26:15 +01:00

34 lines
903 B
Python

from django.core.management.base import BaseCommand
from ...models import Coin
from ...synchronous import (
update_database,
update_dominance,
update_p2pool,
update_rank,
get_history_function,
)
from ...asynchronous import (
get_block_data,
get_coin_data,
get_coinmarketcap_data,
get_network_data,
get_p2pool_data,
get_social_data,
update_others_data,
update_xmr_data,
)
class Command(BaseCommand):
help = "Initializes the database with the latest data"
def handle(self, *args, **options):
Coin.objects.all().delete()
for coin in ["xmr", "btc", "dash", "zec", "grin"]:
try:
self.stdout.write(self.style.SUCCESS(f"Updating {coin} data"))
get_history_function(coin)
except Exception as e:
self.stdout.write(self.style.ERROR(f"Error with {coin}: {e}"))