Fix: removed usage pick(); Refactored map() usage; moved type property into prefix addition

This commit is contained in:
Ludwig Behm 2023-10-18 17:26:25 +02:00
parent f1a7e0dd42
commit 097eaa0500
Signed by: l.behm
GPG key ID: D344835D63B89384
2 changed files with 13 additions and 10 deletions

View file

@ -4,11 +4,11 @@ This oneliner converts streaming optimised jCal format from [rfc7265](https://da
## The actual code ## The actual code
`jq '[(.[2][]|select(.[0] == "vevent")|.[1]|[.[]|{"key": .[0], "value": .[3]}]|from_entries)]'` `jq '.[2] | map({_type: .[0]} + (.[1] | map({key: .[0], value: .[3]}) | from_entries))'`
## Example Usage ## Example Usage
```bash ```bash
curl -sH "Accept: application/calendar+json" https://cloud.kraut.space/remote.php/dav/public-calendars/2EkPGt3PF6WwYsA3\?export\&expand\=1\&start\=$(date -d '' +%s)\&end\=$(date -d 'next month' +%s) \ curl -sH 'Accept: application/calendar+json' https://cloud.kraut.space/remote.php/dav/public-calendars/2EkPGt3PF6WwYsA3\?export\&expand\=1\&start\=$(date -d '' +%s)\&end\=$(date -d 'next month' +%s) \
| jq '[(.[2][]|select(.[0] == "vevent")|.[1]|[.[]|{"key": .[0], "value": .[3]}]|from_entries)]' | jq '.[2]|map({_type:.[0]}+(.[1]|map({key:.[0],value:.[3]})|from_entries))'
``` ```

View file

@ -1,10 +1,13 @@
#!/usr/bin/jq -rfc #!/usr/bin/jq -rfc
[
( .[2] # skipping calender header and accessing events
.[2][] # skipping calender header and accessing events | map( # for each event:
| [["_type", {}, "text", .[0]], .[1][]] # adding ical type like 'vevent' as ._type property {_type: .[0]} # adding ical type like 'vevent' as ._type property
| [.[] | {"key": .[0], "value": .[3]}] | from_entries # transforming event array structure into object structure + (
| pick(._type, .dtstart, .dtend, .summary, .location, .description, .sequence, .["related-to"]) # allow list of properties .[1] # accessing jCal properties; [1] holds name of iCalendar component, i.e. `vevent`; [2] holds additional components
| map({key: .[0], value: .[3]}) | from_entries # transforming event array structure into object structure
# only tested with vevents. pick() isn't supported in jq on debian bookworm
# | pick(.dtstart, .dtend, .summary, .location, .description, .sequence, .["related-to"]) # allow list of properties
)
) )
]
| sort_by(.dtstart|fromdate) # sorting by event start time | sort_by(.dtstart|fromdate) # sorting by event start time