Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
6c09c465
Commit
6c09c465
authored
3 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
calendar utils: Fix parsing alarms
parent
c7466501
No related branches found
No related tags found
2 merge requests
!408
Uniweb kalendáře
,
!407
uniweb calendar
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
calendar_utils/parser.py
+8
-0
8 additions, 0 deletions
calendar_utils/parser.py
tests/calendar_utils/sample.ics
+15
-0
15 additions, 0 deletions
tests/calendar_utils/sample.ics
tests/calendar_utils/test_parser.py
+12
-0
12 additions, 0 deletions
tests/calendar_utils/test_parser.py
with
35 additions
and
0 deletions
calendar_utils/parser.py
+
8
−
0
View file @
6c09c465
import
re
from
operator
import
attrgetter
from
operator
import
attrgetter
import
arrow
import
arrow
...
@@ -7,8 +8,15 @@ from ics import Calendar
...
@@ -7,8 +8,15 @@ from ics import Calendar
EVENT_KEYS
=
(
"
begin
"
,
"
end
"
,
"
all_day
"
,
"
name
"
,
"
description
"
,
"
location
"
)
EVENT_KEYS
=
(
"
begin
"
,
"
end
"
,
"
all_day
"
,
"
name
"
,
"
description
"
,
"
location
"
)
def
remove_alarms
(
source
):
"""
Removes VALARM blocks from iCal source.
"""
return
re
.
sub
(
r
"
(BEGIN:VALARM.*?END:VALARM\r?\n)
"
,
""
,
source
,
flags
=
re
.
S
)
def
parse_ical
(
source
):
def
parse_ical
(
source
):
"""
Parses iCalendar source and returns events as list of dicts.
"""
"""
Parses iCalendar source and returns events as list of dicts.
"""
# there is a bug in parsing alarms, but we don't need them, so we remove them
source
=
remove_alarms
(
source
)
cal
=
Calendar
(
source
)
cal
=
Calendar
(
source
)
events
=
[]
events
=
[]
for
event
in
sorted
(
cal
.
events
,
key
=
attrgetter
(
"
begin
"
),
reverse
=
True
):
for
event
in
sorted
(
cal
.
events
,
key
=
attrgetter
(
"
begin
"
),
reverse
=
True
):
...
...
This diff is collapsed.
Click to expand it.
tests/calendar_utils/sample.ics
+
15
−
0
View file @
6c09c465
...
@@ -70,6 +70,21 @@ SEQUENCE:0
...
@@ -70,6 +70,21 @@ SEQUENCE:0
STATUS:CONFIRMED
STATUS:CONFIRMED
SUMMARY:Setkání s místopředsedou Evropského parlamentu Marcelem Kolalokou
SUMMARY:Setkání s místopředsedou Evropského parlamentu Marcelem Kolalokou
TRANSP:OPAQUE
TRANSP:OPAQUE
BEGIN:VALARM
ACTION:EMAIL
TRIGGER;VALUE=DURATION:-PT1H
SUMMARY:Default Mozilla Summary
DESCRIPTION:Default Mozilla Description
X-LIC-ERROR;X-LIC-ERRORTYPE=PARAMETER-VALUE-PARSE-ERROR:Got a VALUE paramet
er with an illegal type for property: VALUE=DURATION
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER;VALUE=DURATION:-PT30M
DESCRIPTION:Default Mozilla Description
X-LIC-ERROR;X-LIC-ERRORTYPE=PARAMETER-VALUE-PARSE-ERROR:Got a VALUE paramet
er with an illegal type for property: VALUE=DURATION
END:VALARM
END:VEVENT
END:VEVENT
BEGIN:VEVENT
BEGIN:VEVENT
DTSTART:20200301T140000Z
DTSTART:20200301T140000Z
...
...
This diff is collapsed.
Click to expand it.
tests/calendar_utils/test_parser.py
+
12
−
0
View file @
6c09c465
...
@@ -4,6 +4,7 @@ import pytest
...
@@ -4,6 +4,7 @@ import pytest
from
calendar_utils.parser
import
(
from
calendar_utils.parser
import
(
parse_ical
,
parse_ical
,
process_ical
,
process_ical
,
remove_alarms
,
set_event_duration
,
set_event_duration
,
split_events
,
split_events
,
)
)
...
@@ -56,3 +57,14 @@ def test_process_ical(sample, snapshot):
...
@@ -56,3 +57,14 @@ def test_process_ical(sample, snapshot):
past_events
,
future_events
=
process_ical
(
sample
)
past_events
,
future_events
=
process_ical
(
sample
)
snapshot
.
assert_match
(
past_events
)
snapshot
.
assert_match
(
past_events
)
snapshot
.
assert_match
(
future_events
)
snapshot
.
assert_match
(
future_events
)
def
test_remove_alarms
(
snapshot
):
source
=
(
"
BEGIN:VEVENT
\n
content
\n
BEGIN:VALARM
\n
alarm
\n
END:VALARM
\n
END:VEVENT
\n
"
"
BEGIN:VEVENT
\n
other event
\n
BEGIN:VALARM
\n
noooo
\n
END:VALARM
\n
END:VEVENT
"
)
expected
=
(
"
BEGIN:VEVENT
\n
content
\n
END:VEVENT
\n
BEGIN:VEVENT
\n
other event
\n
END:VEVENT
"
)
assert
remove_alarms
(
source
)
==
expected
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment