Python Forum
Script works ok on windows but gives error on ubuntu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script works ok on windows but gives error on ubuntu
#1
A friend of mine wrote this script for me :


#!/usr/bin/env python2.7 
import requests;
import json

# Configurable Variables

#Current mining coin path
MINING_COIN_PATH = './smartMiner_Coin.json';
# Default coin
DEFAULT_COIN = {'tag': "DUAL_SOIL_PASC"};
# Avoid switching for small benefits
PERCENTAGE_VARIED = 10;


def refreshTopCoin():
    # Get current mining coin object
    currentCoin = DEFAULT_COIN;
    with open(MINING_COIN_PATH, 'r') as coinFile:
        currentCoin = json.load(coinFile)
        coinFile.close()

    r = requests.get("https://whattomine.com/coins.json");
    coinsData = r.json()['coins'];
    coins = coinsData.keys();
    topRevenue = {};

    includeTags = ['HUSH', 'ZEC', 'ZEN', 'ZCL', 'SIB', 'XDN', 'LBC' , 'DGB' ]

    filterdCoins = {k: v for k, v in coinsData.iteritems() if v['tag'] in includeTags}
    coins = filterdCoins.keys()

    # print len(filterdCoins)


    def findDifficulty(d1, d2):
        return ((d1 - d2) / ((d1 + d2) / 2)) * 100

    for coin in coins:
        coinObj = coinsData[coin]
        coinObj['smartProfitability'] = coinObj['btc_revenue']
        topRevenue[coin] = coinObj

    # for k in topRevenue:
    #     print topRevenue[k]['tag'], ' - ', topRevenue[k]['smartProfitability']

    # print sorted(filterdCoins.values(), key=lambda d: d['smartProfitability']);

    difficultySort = sorted(filterdCoins.values(), key=lambda d: d['smartProfitability'], reverse=True);

    # print difficultySort;

    topCoin = DEFAULT_COIN;

    if (len(difficultySort) > 1):
        topCoin = difficultySort[0]

    # print topCoin['tag'];
    # print 'Current Coin: ', currentCoin['btc_revenue']
    switchingRequired = isSwitchingRequired(currentCoin=currentCoin, topCoin=topCoin)
    if (switchingRequired):
        updateCoinFile = open(MINING_COIN_PATH, 'w')
        json.dump(topCoin, updateCoinFile, indent=4, sort_keys=True)
        updateCoinFile.close()


def isSwitchingRequired(currentCoin, topCoin):
    print '#Coins: ', currentCoin['tag'], topCoin['tag']
    if (currentCoin['tag'] != topCoin['tag']):
        currentRevenue = float(currentCoin['btc_revenue'])
        topRevenue = float(topCoin['btc_revenue'])
        print '#Revenue: ', currentRevenue, topRevenue
        revenueDiff = ((topRevenue - currentRevenue) / topRevenue) * 100
        print "#Difference in Percentage", revenueDiff
        print "#Switch ", revenueDiff > PERCENTAGE_VARIED
        return revenueDiff > PERCENTAGE_VARIED
    return False

refreshTopCoin()
It works ok on windows but in ubuntu it gives me error :

 python2.7 smartMiner_BTC.py
Traceback (most recent call last):
  File "smartMiner_BTC.py", line 79, in <module>
    refreshTopCoin()
  File "smartMiner_BTC.py", line 20, in refreshTopCoin
    currentCoin = json.load(coinFile)
  File "/usr/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 367, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 27 column 1 - line 27 column 21 (char 812 - 832)
Can any one help please ?
Both have Python 2.7.14

In windows I just changed
MINING_COIN_PATH = './smartMiner_Coin.json';
to:

MINING_COIN_PATH = 'smartMiner_Coin.json';
Reply
#2
Looks like a json parsing error.  Print out the response you're getting, and see if there's any obvious errors in it.
Reply
#3
(Oct-10-2017, 07:47 PM)nilamo Wrote: Print out the response you're getting, and see if there's any obvious errors in it.
I think the error is with file on his drive, not with the json that he gets as a reponse.


as a side note - you don't need coinFile.close() on line#20, because you use with context manager and it will close the file for you.
Reply
#4
Thanks a lot for help
Yes,the problem was the file smartMiner_Coin.json
replaced and its fixed
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  DF.groupby(col).min works, mean gets a "not implemented" error samgardner5 3 500 Feb-29-2024, 06:13 PM
Last Post: deanhystad
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 383 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Python script running under windows over nssm.exe JaroslavZ 0 725 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,376 Jun-18-2022, 01:09 PM
Last Post: snippsat
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,341 May-24-2022, 07:02 AM
Last Post: netanelst
  "SSL: CERTIFICATE_VERIFY_FAILED” error on Python 3.9.6 (Windows 10) rcmv 4 3,688 May-10-2022, 01:18 PM
Last Post: rcmv
  pip error on Ubuntu 18.04.6 LTS silbro 4 1,548 Apr-13-2022, 08:18 AM
Last Post: silbro
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,827 Feb-18-2022, 01:29 PM
Last Post: pstein
  script with imports works but pytest gives "ModuleNotFoundError"? Hpao 0 1,576 Jun-27-2021, 08:30 PM
Last Post: Hpao
  Python script in Ubuntu core Nithin_Kumar 1 3,382 May-11-2021, 01:14 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020