feat(management): add command to initialize chart data
Some checks are pending
Docker / build (push) Waiting to run
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:
parent
cf9779b827
commit
8c779ba5e5
2 changed files with 34 additions and 0 deletions
0
app/charts/management/commands/__init__.py
Normal file
0
app/charts/management/commands/__init__.py
Normal file
34
app/charts/management/commands/initialize_data.py
Normal file
34
app/charts/management/commands/initialize_data.py
Normal 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}"))
|
Loading…
Reference in a new issue