Fix: removed usage pick(); Refactored map() usage; moved type
property into prefix addition
This commit is contained in:
parent
f1a7e0dd42
commit
097eaa0500
2 changed files with 13 additions and 10 deletions
|
@ -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))'
|
||||||
```
|
```
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue