'parse error: Invalid numeric literal at line 1, column 6

The 1 liner to grab the ticker works fine from commandline, but i get this error running in a script.

I run the 1 liner that grabs TICKERD from commandline, that doesnt give me the error.

But, i believe it is because of empty data in the array?

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

Error Message :

./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


Solution 1:[1]

To debug the problem, you could check the output produced by the "curl" command. When I run it in a loop, without jq, the output is frequently "Retry later", as though there is some kind of throttling.

A similar alternative to consider would be to run a very basic jq program, e.g.

#!/bin/bash
for i in {1..15}
do
    newdate=`/bin/date -v +"$i"d +%Y%m%d`
    echo newdate=$newdate
    curl -k -s "https://api.earningscalendar.net/?date=$newdate" | jq type
done

Solution 2:[2]

An empty array will not cause the error message you see.

EDIT: the issue is the API returning retry later as @peak says. To fix this, just add sleep 1 as that seemed to fix it

Here is an example of an empty array being returned but no parse error 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"

Output

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, --

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 peak
Solution 2 serenesat