尝试运行此代码时,我一直遇到问题。有一些帮助,但仍然没有工作。请帮助:)
完整代码:
exports.unicodeAccent = function(str)
{
var charset = [
"€",
"À",
"Á",
"Â",
"Ã",
"Ä",
"Å",
"à",
"á",
"â",
"ã",
"ä",
"å",
"Ò",
"Ó",
"Ô",
"Õ",
"Õ",
"Ö",
"Ø",
"ò",
"ó",
"ô",
"õ",
"ö",
"ø",
"È",
"É",
"Ê",
"Ë",
"è",
"é",
"ê",
"ë",
"ð",
"Ç",
"ç",
"Ð",
"Ì",
"Í",
"Î",
"Ï",
"ì",
"í",
"î",
"ï",
"Ù",
"Ú",
"Û",
"Ü",
"ù",
"ú",
"û",
"ü",
"Ñ",
"ñ",
"Š",
"š",
"Ÿ",
"ÿ",
"ý",
"Ž",
"ž"
];
for(var i = 0; i < charset.length; i++)
{
var code = ("00000000"+(charset[i].charCodeAt(0).toString(16))).slice(-4);
var unicodeStr = "\\u"+code;
var re = new RegExp(charset[i], "gm");
str = str.replace(re, unicodeStr);
}
return str;
}
我不断收到这两个错误:
#!/usr/bin/env python3
from __future__ import print_function
try:
import pymarketcap
import decimal
from operator import itemgetter
import argparse
except Exception as e:
print('Make sure to install {0} (pip3 install {0}).'.format(str(e).split("'")[1]))
exit()
# arguments and setup
parser = argparse.ArgumentParser()
parser.add_argument('-m','--minimum_vol',type=float,help='Minimum Percent volume per exchange to have to count',default=1)
parser.add_argument('-p','--pairs',nargs='*',default=[],help='Pairs the coins can be arbitraged with - default=all')
parser.add_argument('-c','--coins_shown',type=int,default=10,help='Number of coins to show')
parser.add_argument('-e','--exchanges',nargs='*',help='Acceptable Exchanges - default=all',default=[])
parser.add_argument('-s','--simple',help='Toggle off errors and settings',default=False,action="store_true")
args = parser.parse_args()
cmc = pymarketcap.Pymarketcap()
info = []
count = 1
lowercase_exchanges = [x.lower() for x in args.exchanges]
all_exchanges = not bool(args.exchanges)
all_trading_pairs = not bool(args.pairs)
coin_format = '{: <25} {: >6}% {: >10} {: >15} {: <10} {: <10} {: <15} {: <5}'
if not args.simple:
print('CURRENT SETTINGS\n* MINIMUM_PERCENT_VOL:{}\n* TRADING_PAIRS:{}\n* COINS_SHOWN:{}\n* EXCHANGES:{}\n* ALL_TRADING_PAIRS:{}\n* ALL_EXCHANGES:{}\n'.format(args.minimum_vol,args.pairs,args.coins_shown,lowercase_exchanges,all_trading_pairs,all_exchanges))
# retrieve coin data
for coin in cmc.ticker():
try:
markets = cmc.markets(coin["id"])
except Exception as e:
markets = cmc.markets(coin["symbol"])
best_price = 0
best_exchange = ''
best_pair = ''
worst_price = 999999
worst_exchange = ''
worst_pair = ''
has_markets = False
for market in markets:
trades_into = market["pair"].replace(str(coin["symbol"])," ").replace("-"," ")
if market['percent_volume'] >= args.minimum_vol and market['updated'] and (trades_into in args.pairs or all_trading_pairs) and (market['exchange'].lower() in lowercase_exchanges or all_exchanges):
has_markets = True
if market['price_usd'] >= best_price:
best_price = market['price_usd']
best_exchange = market['exchange']
best_pair = trades_into
if market['price_usd'] <= worst_price:
worst_price = market['price_usd']
worst_exchange = market['exchange']
worst_pair = trades_into
if has_markets:
info.append([coin['name'],round((best_price/worst_price-1)*100,2),worst_price,worst_exchange,worst_pair,best_price,best_exchange,best_pair])
elif not args.simple:
print(coin['name'],'had no markets that fit the criteria.')
print('[{}/100]'.format(count),end='\r')
count += 1
# show data
info = sorted(info,key=itemgetter(1))[::-1]
print(coin_format.format("COIN","CHANGE","BUY PRICE","BUY AT","BUY WITH","SELL PRICE","SELL AT","SELL WITH"))
for coin in info[0:args.coins_shown]:
print(coin_format.format(*coin))
非常感谢任何帮助。谢谢 在我之前的问题之前得到了一些很好的帮助,但仍然没有解决方案。
非常感谢任何帮助。谢谢你在我之前的问题之前收到了一些很好的帮助,但还没有解决方案。
答案 0 :(得分:1)
我认为问题在于,如果对某些硬币没有任何东西可以找到(无论你使用coin["id"]
还是coin["symbol"]
),这可能是由建立的死链接引起的进入ticker
模块(coinmarketcap.com/currencies/)。在这种情况下
markets = cmc.markets(coin["id"])
markets = cmc.markets(coin["symbol"])
将抛出AttributeError。您应该将代码更改为
for coin in cmc.ticker():
try:
# this call can fail
markets = cmc.markets(coin["id"])
except AttributeError as e:
try:
# second call could also fail
markets = cmc.markets(coin["symbol"])
except AttributeError as e1:
print("Nothing found for " + coin["id"])
continue #skip this coin?
best_price = 0
我尝试了您的代码,但是对于名为janus
的硬币失败了,当您手动尝试链接时,会显示PageNotFound
,这可以解释为什么它不起作用
答案 1 :(得分:0)
NoneType意味着您实际上获得了None
,而不是您认为自己正在使用的任何类或对象的实例。这通常意味着上面的赋值或函数调用失败或返回意外结果。
如需进一步调查,我建议您打印以下表达式的响应及其类型:
for coin in cmc.ticker():
try:
markets = cmc.markets(coin["id"])
except Exception as e:
markets = cmc.markets(coin["symbol"])
best_price = 0
print(markets)
print(type(markets))
这不会解决您的问题,但可能会让您深入了解困扰您的代码行。并且您可以进一步调试它以确定您的错误。如果问题仍然存在,您可以编辑您的问题并发布进一步评估的代码/追溯调用,这将帮助我们(社区成员)帮助您解决问题。
通常,python中有数据类型,你无法迭代,可能需要以某种可迭代的方式对其进行类型转换(例如,字典,列表)或使用属性来访问你案例中给定索引的值
希望有所帮助:)