diff --git a/charts/models.py b/charts/models.py index 7fa9276..b548ccd 100644 --- a/charts/models.py +++ b/charts/models.py @@ -134,5 +134,16 @@ class DailyData(models.Model): crypto_commentsPerHour = models.FloatField() crypto_postsPerHour = models.FloatField() + def __str__(self): + return self.date + +class P2Pool(models.Model): + date = models.DateField() + hashrate = models.IntegerField() + percentage = models.FloatField() + miners = models.IntegerField() + totalhashes = models.IntegerField() + totalblocksfound = models.IntegerField() + def __str__(self): return self.date \ No newline at end of file diff --git a/charts/views.py b/charts/views.py index 36a7c5d..bd1526b 100644 --- a/charts/views.py +++ b/charts/views.py @@ -1239,6 +1239,48 @@ def update_database(date_from=None, date_to=None): return count +# Get latest P2Pool data +def get_latest_p2pool(): + today = date.today() + yesterday = date.today() - timedelta(1) + today = datetime.datetime.strftime(today, '%Y-%m-%d') + try: + print(1) + P2Pool.objects.get(date=today) + print(2) + return False + except: + print(3) + try: + print(today) + coin = Coin.objects.filter(name='xmr').get(date=yesterday) + print(4) + if coin.hashrate > 0: + print(5) + pass + else: + + print(6) + return False + except: + print(7) + return False + + p2pool_stat = P2Pool() + p2pool_stat.date = today + response = requests.get('https://p2pool.io/api/pool/stats') + + data = json.loads(response.text) + p2pool_stat.hashrate = data['pool_statistics']['hashRate'] + p2pool_stat.percentage = 100*data['pool_statistics']['hashRate']/coin.hashrate + p2pool_stat.miners = data['pool_statistics']['miners'] + p2pool_stat.totalhashes = data['pool_statistics']['3444692929009331,'] + p2pool_stat.totalblocksfound = data['pool_statistics']['totalBlocksFound'] + p2pool_stat.save() + print('p2pool saved!') + + return True + ########################################### # Views ########################################### @@ -1247,6 +1289,7 @@ def index(request): if request.user.username != "Administrador" and request.user.username != "Morpheus": update_visitors(True) + get_latest_p2pool() dt = datetime.datetime.now(timezone.utc).timestamp() symbol = 'xmr' diff --git a/moneropro/settings.py b/moneropro/settings.py index 520af3f..89cc1c1 100644 --- a/moneropro/settings.py +++ b/moneropro/settings.py @@ -32,9 +32,9 @@ STATICFILES_DIRS = [ SECRET_KEY = 'dafsdasdfasfa7sdfs9d7das7f9as7df8ad43525fsffdssdg455$$###77saf9df79as79s' # SECURITY WARNING: don't run with debug turned on in production! -#DEBUG = True -DEBUG = False -STATIC_ROOT = "/var/www/moneropro/static/" +DEBUG = True +#DEBUG = False +#STATIC_ROOT = "/var/www/moneropro/static/" ALLOWED_HOSTS = ['www.moneroj.net', 'localhost', '127.0.0.1', 'moneroj.net', 'ilt7jgmfro76wgrtt6752lvfnhcz6wk5sjqhyvntjixygp3cwpvr4nad.onion']