717
edits
(Update Toadua link to new URL) |
(API / jq example) |
||
Line 27: | Line 27: | ||
== Development == | == Development == | ||
The source code is on [https://github.com/uakci/toadua/ GitHub]. | The source code is on [https://github.com/uakci/toadua/ GitHub]. | ||
== API == | |||
The API is documented [https://github.com/toaq/toadua/blob/main/docs/api.md here]. You can fetch all the data from Toadua using a command like | |||
<syntaxhighlight lang="sh"> | |||
# Unix shell | |||
curl -X POST "https://toadua.uakci.space/api" --data '{"action":"search","query":["and"]}' > toadua.json | |||
# Windows PowerShell | |||
iwr "https://toadua.uakci.space/api" -Method POST -Body '{"action":"search","query":["and"]}' -O toadua.json</syntaxhighlight> | |||
Then, you can use tools like [https://jqlang.org/ jq] to perform all kinds of quick data science. Here is a command to get the most-upvoted word from every month: | |||
<syntaxhighlight lang="sh">jq -r '.results | group_by(.date[:7]) | map({ month: .[0].date[:7], best: max_by(.score).head })' toadua.json</syntaxhighlight> | |||
Or you can use Python: | |||
<syntaxhighlight lang="py">Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] on linux | |||
Type "help", "copyright", "credits" or "license" for more information. | |||
>>> import json | |||
>>> with open("toadua.json") as f: toadua = json.load(f) | |||
... | |||
>>> sum(abs(entry["score"]) for entry in toadua["results"]) | |||
8435 | |||
>>> max(toadua["results"], key=lambda e: e["score"])["body"] | |||
'interjection: nyaan'</syntaxhighlight> |