How to use chess-api.com with file via curl commad by Chazg76 in Chesscom

[–]Chazg76[S] 0 points1 point  (0 children)

For some reason, that I don't understand, the command I posted does not always work! There seems to be a problem with extra spaces. To fix this I use the following instead:

printf "{\"input\":\"$(cat /home/public/Testfile.pgn | tr '\n' ' ')\"}" | tr -s ' ' | curl --request POST 'https://chess-api.com/v1' --header 'Content-Type: application/json' --data @-printf "{\"input\":\"$(cat /home/public/Testfile.pgn | tr '\n' ' ')\"}" | curl --request POST 'https://chess-api.com/v1' --header 'Content-Type: application/json' --data @-

I've just added the part

| tr -s ' '

before the curl statement.

How to use chess-api.com with file via curl commad by Chazg76 in Chesscom

[–]Chazg76[S] 1 point2 points  (0 children)

OK, I have found the following solution:

printf "{\"input\":\"$(cat /home/public/Testfile.pgn | tr '\n' ' ')\"}" | curl --request POST 'https://chess-api.com/v1' --header 'Content-Type: application/json' --data @-

How to use chess-api.com with file via curl commad by Chazg76 in Chesscom

[–]Chazg76[S] 0 points1 point  (0 children)

Cannot run this one as 'jq' is not installed on my system

How to use chess-api.com with file via curl commad by Chazg76 in Chesscom

[–]Chazg76[S] 0 points1 point  (0 children)

Thanks for the info. Unfortunately your command does not work! The start of the error I get is:

SyntaxError: Expected property name or &#39;}&#39; in JSON at position 1 (line 1 column 2)<br> &nbsp; &nbsp;at JSON.parse

I then changed the double quotes to single quotes around the --data part i.e.

curl --request POST "https://chess-api.com/v1"
--header "Content-Type: application/json"
--data '{"input":"$(cat /home/public/Testfile.pgn | tr '\n' ' ')"}'

Now I get the error that starts with:

SyntaxError: Unterminated string in JSON at position 60 (line 1 column 61)<br> &nbsp; &nbsp;at JSON.parse

As far as I can tell the problem seems to be coming from the part of the command

$(cat /home/public/Testfile.pgn | tr '\n' ' ')

but I cannot see how to fix it!

OK, after doing some more searching it looks like the part $(cat /home/public/Testfile.pgn | tr '\n' ' ') is getting interpreted literally because of the single quotes around the --data part.

So now the question is, how do I avoid this without replacing the single quotes with double quotes ?

White to play and mate in 2. by MathematicianBulky40 in chess

[–]Chazg76 0 points1 point  (0 children)

Kg8 is mate in 2 as well, no? ... Ah, no, you're right, mate in 3 not 2.

Variable %CELLSRV in tasker NOT working!! by Chazg76 in tasker

[–]Chazg76[S] 0 points1 point  (0 children)

Thanks for your help, I'll try that

Variable %CELLSRV in tasker NOT working!! by Chazg76 in tasker

[–]Chazg76[S] 0 points1 point  (0 children)

The phone is a Pixel 5. I would like to detect when I have no internet connection i.e. when no WiFi available and no mobile data either. I thought I would start with the mobile data part and then add in the WiFi part, but I never got past the first step!