diff --git a/app/charts/management/commands/__init__.py b/app/charts/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/charts/management/commands/initialize_data.py b/app/charts/management/commands/initialize_data.py new file mode 100644 index 0000000..d17d796 --- /dev/null +++ b/app/charts/management/commands/initialize_data.py @@ -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}"))