commit 60e779e0b864e4c32b66a69135215fa0a05a0bef
parent eff971abce607538c41bff6cc2e4a53e0cb69361
Author: Matthias Balk <mbalk@mbalk.de>
Date: Mon, 17 Sep 2018 19:52:29 +0200
using generator for opening file
Diffstat:
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/commands.py b/commands.py
@@ -74,19 +74,19 @@ def _conv2local(dt):
def print_events(icsfilename):
- f = open(icsfilename)
- for event in vobject.readComponents(f):
- start = _conv2local(event.vevent.dtstart.value)
- end = _conv2local(event.vevent.dtend.value)
-
- try:
- location = " (" + event.vevent.location.value + ")"
- except AttributeError:
- location = ""
-
- if start >= datetime.now(gettz()) - config.MAX_AGE and \
- start < datetime.now(gettz()) + config.MAX_AHEAD:
- print('%s - %s %s%s' % (start.strftime('%Y-%m-%d %H:%M'),
- end.strftime('%H:%M'),
- event.vevent.summary.value,
- location))
+ with open(icsfilename) as f:
+ for event in vobject.readComponents(f):
+ start = _conv2local(event.vevent.dtstart.value)
+ end = _conv2local(event.vevent.dtend.value)
+
+ try:
+ location = " (" + event.vevent.location.value + ")"
+ except AttributeError:
+ location = ""
+
+ if start >= datetime.now(gettz()) - config.MAX_AGE and \
+ start < datetime.now(gettz()) + config.MAX_AHEAD:
+ print('%s - %s %s%s' % (start.strftime('%Y-%m-%d %H:%M'),
+ end.strftime('%H:%M'),
+ event.vevent.summary.value,
+ location))