Open alnerdo opened 7 years ago
I think I figured it out... Habitica seems to be looking for some data along with the curl command. Putting the curl -X POST command into OSX Terminal returns an error 411 (content length or chunking required). Adding "-d ''" to the MAINPOST script seems to get around that and the commands are accepted. It's strange, none of the Habitica API documentation seems to mention that.
Now, if there were a way to show a log of the comments that Habitica returns (e.g. found an item, how much exp or gold gained) that would be amazing.
alnerdo, it seems that I've met this problem too. Could you please give some advice in detail? Which line of code should I change?
@alnerdo
Hello,
If I remember correctly this is the specific line of script that needed to be changed (-d needs to be added to the curl command). To be honest I don’t even know now why that works… I only read enough about Applescript to figure out how to fix it and then promptly forgot everything. Sorry about the delay to respond over the holidays.
set MAINPOST to "curl -X POST --compressed -H 'Content-Type:application/json' -H 'x-api-user:" & API_USER & "' -H 'x-api-key:" & API_KEY & "' -d '' "
Regards,
Albert
On Dec 21, 2017, at 12:02 AM, tianshanghong <notifications@github.com mailto:notifications@github.com> wrote:
alnerdo, it seems that I've met this problem too. Could you please give some advice in detail? Which line of code should I change?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Matthewspear/OmniRPG/issues/17#issuecomment-353258839, or mute the thread https://github.com/notifications/unsubscribe-auth/AdNuBG7AjPl24q88RvEfHh_g-Q950p9Tks5tCeZTgaJpZM4OqD0c.
https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png https://github.com/Matthewspear/OmniRPG https://github.com/Matthewspear/OmniRPG/issues/17#issuecomment-353258839
@alnerdo I know this is getting further and further into the past and you're likely not to remember, but: do you know if you changed anything else in the script? I've made that change and find that it still does not properly update stats in Habitica. Thanks for your help!
Hello,
This is the script that I have been using… it works for me. You just have to enter your own user ID and API key. I think this is the only other line that had to be changed from the original script:
set MAINPOST to "curl -X POST --compressed -H 'Content-Type:application/json' -H 'x-api-user:" & API_USER & "' -H 'x-api-key:" & API_KEY & "' -d '' "
Regards,
Albert
set dateToday to date (short date string of (current date))
set API_USER to "" set API_KEY to ""
tell application "OmniFocus" tell default document set refDoneToday to a reference to (flattened tasks where (completion date ≥ dateToday)) set {lstName, lstContext, lstProject, lstNote} to {name, name of its context, name of its containing project, note} of refDoneToday
-- total number of tasks completed
set n to count of refDoneToday
set low to 0
set medium to 0
set high to 0
repeat with iTask from 1 to count of lstName
set {strName, varContext, varProject, varNote} to {item iTask of lstName, item iTask of lstContext, item iTask of lstProject, item iTask of lstNote}
if varNote contains "LOW" or varContext is "C priority" or varContext is "Low" or varContext is "C" then
set low to low + 1
end if
if varNote contains "MEDIUM" or varContext is "B priority" or varContext is "Medium" or varContext is "B" then
set medium to medium + 1
end if
if varNote contains "HIGH" or varContext is "A priority" or varContext is "High" or varContext is "A" then
set high to high + 1
end if
end repeat
-- tasks that are undefined counted as LOW
set other to n - low - medium - high
end tell
end tell
try -- Print number of tasks completed today tell application "OmniFocus" display dialog "Tasks completed today: " & n & " Low: " & low + other & " Medium: " & medium & " High: " & high
end tell
if button returned of result is "OK" then
-- scripts to trigger HabitRPG
set TASKURL to "https://habitica.com/api/v3/tasks/ <https://habitica.com/api/v3/tasks/>"
set MAINPOST to "curl -X POST --compressed -H 'Content-Type:application/json' -H 'x-api-user:" & API_USER & "' -H 'x-api-key:" & API_KEY & "' -d '' "
set lowScript to MAINPOST & TASKURL & "omnitica-low" & "/score/up"
set mediumScript to MAINPOST & TASKURL & "omnitica-medium" & "/score/up"
set highScript to MAINPOST & TASKURL & "omnitica-high" & "/score/up"
-- repeat scripts per number of completed tasks in each difficulty
repeat low + other times
do shell script lowScript
end repeat
repeat medium times
do shell script mediumScript
end repeat
repeat high times
do shell script highScript
end repeat
end if
-- TODO: write to log
on error number -128
-- do nothing
end try
On Jan 29, 2018, at 2:36 PM, kasmiman <notifications@github.com mailto:notifications@github.com> wrote:
@alnerdo https://github.com/alnerdo I know this is getting further and further into the past and you're likely not to remember, but: do you know if you changed anything else in the script? I've made that change and find that it still does not properly update stats in Habitica. Thanks for your help!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Matthewspear/OmniRPG/issues/17#issuecomment-361360674, or mute the thread https://github.com/notifications/unsubscribe-auth/AdNuBHM3zQITn0LHzglUVUkvU32wMEODks5tPh2mgaJpZM4OqD0c.
https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png https://github.com/Matthewspear/OmniRPG https://github.com/Matthewspear/OmniRPG/issues/17#issuecomment-361360674
Hi Albert,
Thanks! Strange - I'll do some further investigation to see what could be tripping it up.
// Katrina
Habitica expects the content length of the body to be specified:
HTTP Error 411. The request must be chunked or have a content length.
Adding -d ''
works because it sends an empty body.
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)" number 92
I met this issue when I run the Setup.scpt
script.
Sadly this project is 'as is' – I've since moved on from using both Habitica (was called HabitRPG when I used it) and also OmniFocus. For that reason I no longer maintain this repo but have left it online incase anyone wants to work on it.
Feel free to fork the project or make a pull request if you find a solution!
Hello,
I just joined GitHub to try to get some help with this... I use both Habitica and Omnifocus so I was excited to find this program. I think the setup script worked because I saw the Low, Medium, and High difficulty habits in my Habitica. The script seems to be counting Omnifocus tasks correctly, but when I confirm with "OK" I am not seeing any changes in Habitica although there is no error reported... just wondering if there is still support for OmniRPG. Maybe Habitica has changed something on their end? I wish I knew how Applescript works so I could try to figure out what is not working.
Thanks.