Add core.query/serialize?
See original GitHub issueNot sure if this is something youβd be interesting in having in the core here/in utils, is the leftover helper modules I created while maintaining my fork.
As I was writing HPI_API
I added a core.serialize
and core.query
to my HPI fork as well.
It is quite magical (as it just resolves the function name with a string) but it lets me do some simple queries pretty easily, and play around with pipelines in the shell without having to worry about how to interop with python/dumping something from the REPL
https://github.com/seanbreckenridge/HPI/blob/master/my/utils/query.py https://github.com/seanbreckenridge/HPI/blob/master/my/utils/serialize.py
and then a script that exposes that info:
https://github.com/seanbreckenridge/HPI/blob/master/scripts/hpi_query
As some examples, 5 songs I listened to recently:
$ hpi_query my.mpv history | jq -r '.[] | .path' | grep -i 'music' | head -n 5
/home/sean/Music/Radiohead/1994 - The Bends/11 - Sulk.mp3
/home/sean/Music/Radiohead/1994 - The Bends/02 - The Bends.mp3
/home/sean/Music/Nujabes/Nujabes - Metaphorical Music (2003) [V0]/10. Next View.mp3
/home/sean/Music/Earth, Wind & Fire/Earth Wind And Fire - Greatest Hits - [MP3-V0]/16 - After The Love Has Gone.mp3
/home/sean/Music/Darren Korb/Darren Korb - Transistor Original Soundtrack[2013] (V0)/14 - Darren Korb - Apex Beat.mp3
I also use this in my menu bar, to print how many calories/water Iβve drank today:
Like:
#!/bin/bash
# how many water I've had today
((BLOCK_BUTTON == 3)) && notify-send "$("${REPOS}/HPI/scripts/water-recent")"
HPI_QUERY="${REPOS}/HPI/scripts/hpi_query"
{
"${HPI_QUERY}" --days 1 'my.food' 'water' | jq -r '.[] | .glasses'
echo 0
} | datamash sum 1
Have even had some fun creating graphs like this in the terminal:
hpi_query my.food food | jq -r '.[] | "\(.on)\t\(.calories)"' | datamash groupby 1 sum 2 | sort | termgraph | head
2020/09/26: ββββββββββββββββββ 1380.00
2020/09/27: βββββββββββββββ 1150.00
2020/09/28: βββββββββββββββ 1155.00
2020/09/29: ββββββββββββββββββββββββββββ 2200.00
2020/09/30: βββββββββββ 870.00
2020/10/01: ββββββββββββββ 1070.00
2020/10/02: ββββββ 505.00
2020/10/03: βββββββββββββ 995.00
2020/10/04: ββββββββ 640.00
could probably remove the click
/simplejson
dependencies, they were just thrown in there because it was fast and I always have those installed anyways
Maybe query
could be a subcommand on the hpi
script? instead of installing it as a separate script
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:15 (15 by maintainers)
Only remaining task for this issue is to create a
CLI
for query. to combinemy.core.query.select
andmy.core.serialize.dumps
, (and probably creating a couple helper functions inmy.core.query
to glue the two together)I think I can implement that well enough in
argparse
for now, and the switch toclick
can be laterAh right. Could also use a combination of all three of these approaches. The hook approach also seems fine, would just require looping over the (I assume top-level) dict in the module in
default
function.Defining a hook in the source module seems a bit too hacky/magical, as
my.core.serialize
may needimportlib
machinery then?Will try to implement