从命令行获取1条划线器的效果很好,但是我在脚本中运行此错误。
我运行了从命令行抓取TICKERD的1个班轮,但这没有给我错误。
但是,我相信是因为数组中的数据为空吗?
curl -k -s https://api.earningscalendar.net/?date=20190518
[]
#!/bin/bash
for i in {1..15}
do
newdate=`/bin/date -v +"$i"d +%Y%m%d`
TICKERD=`curl -k -s https://api.earningscalendar.net/?date=$newdate | jq -r 'map([.ticker, .when] | join(", ")) | join("\n")' | grep -w "$1"`
TICKERA=`echo $TICKERD | cut -d, -f1`
if [ "$TICKERA" == "$1" ]
then
echo $TICKERD "is on" $newdate
exit
fi
done
错误消息:
./earnings.sh ADSK
parse error: Invalid numeric literal at line 1, column 6
parse error: Invalid numeric literal at line 1, column 6
parse error: Invalid numeric literal at line 1, column 6
parse error: Invalid numeric literal at line 1, column 6
ADSK, amc is on 20190523
答案 0 :(得分:1)
空数组不会导致您看到错误消息。
编辑:问题是API稍后如@peak所述返回重试。要解决此问题,只需添加sleep 1即可解决问题
这是一个返回空数组但没有解析错误的示例
curl -k -s https://api.earningscalendar.net/?date=20190303 | jq -r 'map([.ticker, .when] | join(", ")) | join("\n")' | grep -w "$1"
newdate=`date +%Y%m%d`
curl -k -s https://api.earningscalendar.net/?date=$newdate | jq -r 'map([.ticker, .when] | join(", ")) | join("\n")' | grep -w "$1"
输出
ACB, amc
TLRY, amc
CYBR, bmo
NEWR, amc
AEYE, amc
A, amc
USAT, --
RL, bmo
HUD, bmo
CATB, bmo
ROSE, amc
PAGS, amc
HDB, --
KOOL, amc
CPIX, amc
NLST, amc
AUPH, amc
VCTR, amc
ONCE, --
EVC, --
FSM, amc
JAPAY, --
VLVLY, --
RDSMY, --
ZLNDY, --
GNMSF, --
DOX, amc
PORBF, --
GDS, bmo
EGHT, amc
BEST, bmo
TAC, bmo
TIER, --
GOSS, bmo
AZZ, bmo
TRWH, amc
MDOMF, --
AUTL, bmo
ROAN, amc
CPLG, amc
CTST, bmo
DSSI, bmo
IMXI, amc
TCS, amc
MIXT, bmo
KDMN, --
SFST, --
ALLT, bmo
ARA, --
KMDA, bmo
OCX, amc
MXWL, --
HYGS, bmo
PANL, amc
MTNB, bmo
LIQT, bmo
APTX, bmo
REED, amc
MRBK, --
UQM, amc
GECC, bmo
TGEN, bmo
ENT, amc
MOGO, amc
SLGG, amc
EYEN, bmo
HCAP, bmo
WYY, amc
BLRX, bmo
SUNW, amc
TST, bmo
AYTU, bmo
XELB, bmo
ONTX, bmo
FTD, --
TCON, amc
CYTR, --
YOGA, amc
DYNT, bmo
CYCC, amc
DARE, amc
ESEA, --
EMES, --
ASCMA, --
NSPR, bmo
OPGN, amc
AGHC, --
LIOPF, --
答案 1 :(得分:1)
要调试该问题,可以检查“ curl”命令产生的输出。当我在没有jq的情况下循环运行它时,输出通常是“稍后重试”,就像有某种节流一样。
要考虑的类似替代方法是运行一个非常基本的jq程序,例如
\d{1,}(?:\,?\d{3})*