feat(management): add command to initialize chart data
Some checks are pending
Docker / build (push) Waiting to run

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.
This commit is contained in:
Kumi 2024-11-13 14:26:15 +01:00
parent cf9779b827
commit 8c779ba5e5
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,34 @@
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}"))