EthMiner

Image preview of EthMiner plugin.

ethminer.5s.py

Edit
Open on GitHub
#!/usr/bin/env python3

# <xbar.title>EthMiner</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Cédric Foellmi</xbar.author>
# <xbar.author.github>onekiloparsec</xbar.author.github>
# <xbar.desc>Start and stop the ethminer.</xbar.desc>
# <xbar.image>https://i.imgur.com/DeWnKKf.png</xbar.image>
# <xbar.dependencies>python3,psutil,ethminer</xbar.dependencies>

##############################################################################
### SETUP ###
# 0. Install the ethminer executable.
#    For instance from https://github.com/ArtSabintsev/Ethminer-for-macOS
#
# 1. Create a shell script with the full ethminer command, using the executable above.
#    For instance 'ethmining.sh', with the ethminer executable inside "~/bin":
#    Note also the last part '>& /tmp/ethmining.log':
#
# #!/bin/bash
# /Users/<YourName>/bin/ethminer -G -t 2 -v 2 -S <PoolAddress> -u <UserName> >& /tmp/ethmining.log
#
# 2. Make the script executable: chmod 755 ethmining.sh
#
# 3. Fill the MINING_SCRIPT_FULL_PATH variable below. It is important to provide
# the full path of the script. No ~, no ./... etc.
#
# 4. Make sure MINING_LOG_FULL_PATH points to the same file as the last part of the script above.
#
# 5. Consider a small tip, thanks! :-) ETH: 0x1Dd0e805a5DC21e40B28D4763c6Af790cd6bcd33
##############################################################################

import os

##############################################################################
# Customize your variables here
MINING_SCRIPT_NAME = "ethmining.sh"
MINING_SCRIPT_FULL_PATH = "{}/bin/{}".format(os.environ['HOME'], MINING_SCRIPT_NAME)
MINING_LOG_FULL_PATH = "/tmp/ethmining.log"
MINING_LOG_LINES_NUMBER = "10" # MUST BE LARGER THAN 0
##############################################################################

import re
import psutil
import subprocess

started = 'ethminer' in [ p.name() for p in psutil.process_iter(attrs=['name']) ]
ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')

print("| templateImage=iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAVlp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+7tfXv1vli8CZMw8Tz/HHy4AtM4Y7PZLhQKhSHWIkY3Uc3lcuiHesRsuiYMhdBx3l4Mra0VZ2Zn38AE3oqSdAfA1xGM+rEWvj9TCAQCMj6W9fX1LmPgfOCBbSQMXzOE5GRFtlstlksAboAMA+jXHhsSTEUwGNSe6+bmsxTIUc+e86gLiwsvfxfqpk/hxgnQqftCPdjY+HR+ZaUFhxoQxq1LHtdPJWBkuh/UUBCu2nneD9US6gYCbXRjNCx+ArWREQKYptF1AAAAAElFTkSuQmCC")
print("---")

if started is True:
    print("Stop ethminer | terminal=false bash=/usr/bin/killall param1=ethminer")
else:
    print("Start ethminer | terminal=false bash=\"{}\"".format(MINING_SCRIPT_FULL_PATH))

print("---")

if started is True:
    print("Running !")

proc = subprocess.run(['tail', '-'+MINING_LOG_LINES_NUMBER, MINING_LOG_FULL_PATH], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if proc.returncode == 0:
    if not started:
        print("Last log lines of the previous session:")

    for line in proc.stdout.split(b'\n'):
        s = line.replace(b'|', b' ').replace(b'\xe2\x84\xb9', b' ')
        print(s.decode('utf8'))