Last active
February 28, 2018 08:48
-
-
Save notdodo/ae487b6dd02f0dd0a4295abedfed451a to your computer and use it in GitHub Desktop.
Check current informations from ethermine API and ETH/EUR value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import aiohttp | |
import asyncio | |
import async_timeout | |
import datetime | |
from colored import fg, stylize, attr | |
wallet_address = "ADDRESS" | |
urlAPI = "https://api.ethermine.org/miner/{}".format(wallet_address) | |
coinbase = "https://www.coinbase.com/api/v2/prices/ETH-EUR/spot" | |
k = pow(10, 18) | |
async def fetch(session, url): | |
with async_timeout.timeout(10): | |
async with session.get(url) as response: | |
return await response.json() | |
async def main(): | |
async with aiohttp.ClientSession() as session: | |
stats = await fetch(session, urlAPI + "/currentStats") | |
eth = await fetch(session, coinbase) | |
if stats['status'] == 'OK' and stats['data'] != 'NO DATA': | |
print("ETH: {} €".format( | |
stylize(eth['data']['amount'], fg("blue")))) | |
if float(eth['data']['amount']) > 1000: | |
n = Notify.Notification.new("Current Price", "<b>{}</b> €".format( | |
eth['data']['amount']), "dialog-information") | |
n.show() | |
print("Balance: {}".format( | |
stylize(stats['data']['unpaid'] / k, | |
fg("red_1") + attr("bold")))) | |
if not stats['data']['reportedHashrate'] is None: | |
print("AVG Hashrate: {} MH/s".format( | |
stylize( | |
int(stats['data']['averageHashrate'] / 1000000), | |
fg("green") + attr("bold")))) | |
print("Reported HR: {} MH/s".format( | |
int(stats['data']['reportedHashrate'] / 1000000))) | |
print("$/day: {}".format( | |
stylize(stats['data']['usdPerMin'] * 60 * 24, | |
fg("yellow")))) | |
try: | |
time = datetime.datetime.now() | |
lastSeen = stats['data']['lastSeen'] | |
value = int( | |
abs(time - datetime.datetime.fromtimestamp(lastSeen)) | |
.seconds / 60) | |
if value > 60: | |
print("Last updated: {} h".format(int(value / 60))) | |
else: | |
print("Last updated: {} m".format(value)) | |
except TypeError: | |
pass | |
else: | |
print(stylize("No available informations", fg("yellow"))) | |
if __name__ == "__main__": | |
loop = asyncio.get_event_loop() | |
try: | |
loop.run_until_complete(main()) | |
finally: | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment