Oct-05-2017, 11:09 AM
Hi Guys
I'm very new to python and need help
I forked this from another project and need your expert help to optimize it.
Scripts works on nvOC mining os by fullzero : https://bitcointalk.org/index.php?topic=1854250
The code main job is to get data from whattomine.com json api and check which coin from selection is the best for mining now.
It is doing it now but what I now need is to not switch if the profit is lower than a given percent
So for examlpe if I set percent to 10 if coin A is making 100 and coin B making 105 it wont switch from A to B and stay on A untill B goes higher 110
So for this to work, I think it should check the last top coin which is logged to a file (I set it as top_coin), check and compare with new result then print to file the new coin so the bash script can read from it and switch if needed
These are the scripts
python script:
I'm very new to python and need help
I forked this from another project and need your expert help to optimize it.
Scripts works on nvOC mining os by fullzero : https://bitcointalk.org/index.php?topic=1854250
The code main job is to get data from whattomine.com json api and check which coin from selection is the best for mining now.
It is doing it now but what I now need is to not switch if the profit is lower than a given percent
So for examlpe if I set percent to 10 if coin A is making 100 and coin B making 105 it wont switch from A to B and stay on A untill B goes higher 110
So for this to work, I think it should check the last top coin which is logged to a file (I set it as top_coin), check and compare with new result then print to file the new coin so the bash script can read from it and switch if needed
These are the scripts
python script:
#!/usr/bin/env python2.7 #_*_ coding: utf-8 _*_ #### Whattomine auto switch python script written by papampi, forked from smartminer by damNmad import requests; data = requests.get("https://whattomine.com/coins.json); coinsData = data.json()['coins']; coins = coinsData.keys(); highBTCrev = {}; includeTags = [ 'ZEC', 'ZEN', 'ZCL', 'SIB' , 'LBC' ] filterdCoins = {k: v for k, v in coinsData.iteritems() if v['tag'] in includeTags} coins = filterdCoins.keys() def findBTCrev(d1): return (d1) for coin in coins: coinObj = coinsData[coin] coinObj['smartProfitability'] = findBTCrev(coinObj['btc_revenue']) highBTCrev[coin] = coinObj for k in highBTCrev: print highBTCrev[k]['tag'], ' - ', highBTCrev[k]['smartProfitability'] BTCrevenueSort = sorted(filterdCoins.values(), key=lambda d: d['smartProfitability'],reverse=True); if (len(BTCrevenueSort) > 1): finalCoin = BTCrevenueSort[0] log=open("top_coin", "w") log.write(finalCoin['tag']) log.close()bash script:
#!/bin/bash #### Whattomine auto switch bash script written by papampi source ~/1bash BITCOIN="theGROUND" # Creating a log file to record coin switch LOG_FILE="/home/m1/8_wtmautoswitchlog" if [ -e "$LOG_FILE" ] ; then #Limit the logfile, just keep the last 2K LASTLOG=$(tail -n 2K $LOG_FILE) echo "$LASTLOG" echo "" fi while [ $BITCOIN == "theGROUND" ] do CURRENT_COIN=$(head -n 150 /home/m1/1bash | grep COIN= | sed 's/COIN=//' | sed 's/\"//' | sed 's/\"//') TOP_COIN=$(cat /home/m1/top_coin) TIMEIN=$WTM_AUTO_SWITCH_SYNC_INTERVAL TIMEOUT=$(($TIMEIN * 60)) python2.7 WTM_AUTO_SWITCH.py sleep 5 if [ "$CURRENT_COIN" != "$TOP_COIN" ] then sed -i 's/'COIN=\"$CURRENT_COIN\"'/'COIN=\"$TOP_COIN\"/'' /home/m1/1bash sleep 2 pkill -e screen pkill -f 3main echo "" echo "$(date) Mining switched from $CURRENT_COIN to $TOP_COIN" | tee -a ${LOG_FILE} echo "Check again in $TIMEOUT seconds"# | tee -a ${LOG_FILE} sleep $TIMEOUT else echo "$(date) Same Coin on Top, Continue mining $CURRENT_COIN" | tee -a ${LOG_FILE} echo "Check again in $TIMEOUT seconds" #| tee -a ${LOG_FILE} sleep $TIMEOUT fi done