question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add core.query/serialize?

See original GitHub issue

Not 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:

image

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
seanbreckenridgecommented, Mar 28, 2021

Only remaining task for this issue is to create a CLI for query. to combine my.core.query.select and my.core.serialize.dumps, (and probably creating a couple helper functions in my.core.query to glue the two together)

I think I can implement that well enough in argparse for now, and the switch to click can be later

1reaction
seanbreckenridgecommented, Mar 18, 2021

classes are often β€˜forwarded’ from the original modules

Ah 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 need importlib machinery then?

Will try to implement

Read more comments on GitHub >

github_iconTop Results From Across the Web

.serialize() | jQuery API Documentation
The .serialize() method creates a text string in standard URL-encoded notation. It can act on a jQuery object that has selected individual form...
Read more >
$(this).serialize() -- How to add a value? - Stack Overflow
Any ideas on how you can add an item to the serialize string? This is a global page variable that isn't form specific....
Read more >
Save and Load
We'll add 2 new features. Copy the compressed output of the serialized Nodes to the user's clipboard; Load the editor state from a...
Read more >
@craftjs/core - npm
A React Framework for building extensible drag and drop page editors. Latest version: 0.2.0-beta.8, last published: a month ago. Start using @craftjs/core ......
Read more >
Serialize a Firestore query for execution elsewhere
Deserialize a query created by Query.Serialize deserializedQuery, err := client.CollectionGroup("").Deserialize(bytes) if err != nil { return fmt.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found