Merge branch 'main' of github.com:cryptomorpheuss/moneropro into main

This commit is contained in:
anon 2022-08-08 21:46:42 -03:00
commit d88c4a87d6
2 changed files with 54 additions and 0 deletions

View file

@ -136,3 +136,14 @@ class DailyData(models.Model):
def __str__(self): def __str__(self):
return self.date 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

View file

@ -1239,6 +1239,48 @@ def update_database(date_from=None, date_to=None):
return count 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 # Views
########################################### ###########################################
@ -1247,6 +1289,7 @@ def index(request):
if request.user.username != "Administrador" and request.user.username != "Morpheus": if request.user.username != "Administrador" and request.user.username != "Morpheus":
update_visitors(True) update_visitors(True)
get_latest_p2pool()
dt = datetime.datetime.now(timezone.utc).timestamp() dt = datetime.datetime.now(timezone.utc).timestamp()
symbol = 'xmr' symbol = 'xmr'