我正在尝试编写一个bash脚本,该脚本可以调整为最有利可图的加密货币来挖掘和更改即时挖掘的内容。
我使用curl
使用curl
脚本从http://whattomine.com/coins.json获取API信息:
curl whattomine.com/coins.json -O | > coins.json
示例API:
{"coins":{"Nicehash-Ethash":{"id":15,"tag":"NICEHASH","algorithm":"Ethash","block_time":1,"block_reward":1,"block_reward24":1,"last_block":0,"difficulty":1,"difficulty24":1,"nethash":5595177528830,"exchange_rate":0.0084,"exchange_rate24":0.0086,"exchange_rate_vol":38.522578574534,"exchange_rate_curr":"BTC","market_cap":"$0.00","estimated_rewards":"0.00071","estimated_rewards24":"0.00072","btc_revenue":"0.0007056","btc_revenue24":"0.0007224","profitability":95,"profitability24":101,"lagging":false,"timestamp":1518385271},"EthereumClassic":{"id":162,"tag":"ETC","algorithm":"Ethash","block_time":"14.5606","block_reward":3.88,"block_reward24":3.88000000000005,"last_block":5372259,"difficulty":119798042603096.0,"difficulty24":118354683854950.0,"nethash":8227548494093,"exchange_rate":0.003034,"exchange_rate24":0.00285318393234672,"exchange_rate_vol":2318.70107084,"exchange_rate_curr":"BTC","market_cap":"$2,525,050,483.01","estimated_rewards":"0.23506","estimated_rewards24":"0.23792","btc_revenue":"0.00071316","btc_revenue24":"0.00072186","profitability":96,"profitability24":101,"lagging":false,"timestamp":1518385186},"Ethereum":{"id":151,"tag":"ETH","algorithm":"Ethash","block_time":"14.529","block_reward":2.91,"block_reward24":2.91000000000001,"last_block":5073173,"difficulty":2.86396845523669e+15,"difficulty24":2.96145362923571e+15,"nethash":197120824229932,"exchange_rate":0.100691,"exchange_rate24":0.100200274841438,"exchange_rate_vol":12443.48347244,"exchange_rate_curr":"BTC","market_cap":"$81,928,528,426.15","estimated_rewards":"0.00737","estimated_rewards24":"0.00713","btc_revenue":"0.00074252","btc_revenue24":"0.00071808","profitability":100,"profitability24":100,"lagging":false,"timestamp":1518385171},"Expanse":{"id":154,"tag":"EXP","algorithm":"Ethash","block_time":"45.0","block_reward":4.0,"block_reward24":4.0,"last_block":975425,"difficulty":13101309242779.0,"difficulty24":14838722424377.6,"nethash":291140205395,"exchange_rate":0.00033176,"exchange_rate24":0.000334064524312897,"exchange_rate_vol":10.94411548,"exchange_rate_curr":"BTC","market_cap":"$21,877,350.59","estimated_rewards":"2.2152","estimated_rewards24":"1.9559","btc_revenue":"0.00073491","btc_revenue24":"0.00064889","profitability":99,"profitability24":90,"lagging":false,"timestamp":1518383559},"Pirl":{"id":211,"tag":"PIRL","algorithm":"Ethash","block_time":"14.0","block_reward":10.0,"block_reward24":10.0,"last_block":825434,"difficulty":16734197347723.0,"difficulty24":16762811072321.5,"nethash":1195299810551,"exchange_rate":0.00014626,"exchange_rate24":0.000155109957716702,"exchange_rate_vol":12.9604288790783,"exchange_rate_curr":"BTC","market_cap":"$12,081,862.82","estimated_rewards":"4.33668","estimated_rewards24":"4.32928","btc_revenue":"0.00063428","btc_revenue24":"0.0006332","profitability":85,"profitability24":88,"lagging":false,"timestamp":1518385184},"Musicoin":{"id":178,"tag":"MUSIC","algorithm":"Ethash","block_time":"14.0","block_reward":246.2,"block_reward24":246.199999999998,"last_block":1953827,"difficulty":6613543703874.0,"difficulty24":6686438484420.37,"nethash":472395978848,"exchange_rate":2.34e-06,"exchange_rate24":2.29601694915254e-06,"exchange_rate_vol":17.78104309,"exchange_rate_curr":"BTC","market_cap":"$11,918,018.41","estimated_rewards":"270.12802","estimated_rewards24":"267.18363","btc_revenue":"0.0006321","btc_revenue24":"0.00062521","profitability":85,"profitability24":87,"lagging":false,"timestamp":1518385185},"Ellaism":{"id":221,"tag":"ELLA","algorithm":"Ethash","block_time":"14.0","block_reward":4.91,"block_reward24":4.91000000000001,"last_block":945964,"difficulty":4376186239122.0,"difficulty24":4319302576114.62,"nethash":312584731365,"exchange_rate":7.501e-05,"exchange_rate24":7.6147420718816e-05,"exchange_rate_vol":1.27998339143897,"exchange_rate_curr":"BTC","market_cap":"$2,958,733.31","estimated_rewards":"8.14071","estimated_rewards24":"8.24789","btc_revenue":"0.00061063","btc_revenue24":"0.00061867","profitability":82,"profitability24":86,"lagging":false,"timestamp":1518385172}
我想使用profitability24
字段。
现在我有一个json我需要的信息,我在解决如何获取最有利可图的货币时遇到了很多问题(它始终是json中的第一个)。我的计划是使用jq,但我对这些想法持开放态度。我的下一步是改变最有利可图的货币,然后编写适当的命令让矿工开始挖掘该货币。
答案 0 :(得分:2)
假设您的数据结构是这样的:
$ cat test.json
{"coins" : { "coin1": { "id": 4, "profitability24": 3 },
"coin2": { "id": 5, "profitability24": 2 },
"coin3": { "id": 6, "profitability24": 1 } } }
你想提取'盈利能力24的最大值,我只是将字典过滤成一个列表,然后将其传递给max_by
(你读过the jq docs吗?):
$ cat test.json | jq '[.coins[]]|max_by(.profitability24)'
{
"id": 4,
"profitability24": 3
}
答案 1 :(得分:2)
由于您指明所需的项目是"始终是第一个",您只需写下:
first(.coins[])
如果你想确保总是选择一个最大对象,你可以写:
[.coins[]] | max_by(.profitability24)
(对于样本数据,这两种方法给出了不同的答案,因为有两个最大对象。)
如果你想要所有最大对象,那么一种方法是定义和使用maximals_by(s; f)
,如下所示:
# Emit a stream of the maximal entities in the stream, s:
def maximals_by(s; f):
reduce s as $x ({v:null, a:[]};
($x|f) as $y
| if $y == .v then .a += [$x] elif $y > .v then {v:$y, a: [$x]} else . end)
| .a[];
maximals_by(.coins[]; .profitability24)
使用给定数据,最后一种方法产生两个最大项:
{
"id": 15,
"tag": "NICEHASH",
"algorithm": "Ethash",
"block_time": 1,
"block_reward": 1,
"block_reward24": 1,
"last_block": 0,
"difficulty": 1,
"difficulty24": 1,
"nethash": 5595177528830,
"exchange_rate": 0.0084,
"exchange_rate24": 0.0086,
"exchange_rate_vol": 38.522578574534,
"exchange_rate_curr": "BTC",
"market_cap": "$0.00",
"estimated_rewards": "0.00071",
"estimated_rewards24": "0.00072",
"btc_revenue": "0.0007056",
"btc_revenue24": "0.0007224",
"profitability": 95,
"profitability24": 101,
"lagging": false,
"timestamp": 1518385271
}
{
"id": 162,
"tag": "ETC",
"algorithm": "Ethash",
"block_time": "14.5606",
"block_reward": 3.88,
"block_reward24": 3.88000000000005,
"last_block": 5372259,
"difficulty": 119798042603096,
"difficulty24": 118354683854950,
"nethash": 8227548494093,
"exchange_rate": 0.003034,
"exchange_rate24": 0.00285318393234672,
"exchange_rate_vol": 2318.70107084,
"exchange_rate_curr": "BTC",
"market_cap": "$2,525,050,483.01",
"estimated_rewards": "0.23506",
"estimated_rewards24": "0.23792",
"btc_revenue": "0.00071316",
"btc_revenue24": "0.00072186",
"profitability": 96,
"profitability24": 101,
"lagging": false,
"timestamp": 1518385186
}