Permalink
Browse files

added support for skipping events that are greater than a specified d…

…uration
  • Loading branch information...
1 parent d894cab commit d934142228f5e7406926c764cef47eca4f0d9a89 Tommy Bishop committed Apr 1, 2010
Showing with 21 additions and 8 deletions.
  1. +2 −1 README
  2. +19 −7 icalreport.py
View
3 README
@@ -7,6 +7,7 @@ Options:
-m MONTH Number of the month for which to report (default: current)
-u MONTH Number of the month until which to report (default: current)
-w Report for the current week
+ -s NUMBER Skip items which are longer than this number of hours
-l Look for projects in events locations (default: titles)
Purpose:
@@ -16,7 +17,7 @@ Options:
$ icalreport -c MyHours -m 9 -u 10 -l
Example:
- $ icalreport -c MyHours -w
+ $ icalreport -c MyHours -w -s 8
$ python icalreport.py -c "Heures_2009" -l
View
@@ -30,7 +30,7 @@ def __init__(self, cal_name, field='title'):
print "Error: %d calendars with title %s" % (len(self.calendars), self.cal_name)
sys.exit(1)
- def print_digest(self, start_date, stop_date):
+ def print_digest(self, start_date, stop_date, event_duration_limit):
predicate = CalCalendarStore.eventPredicateWithStartDate_endDate_calendars_(start_date, stop_date, self.calendars)
@@ -40,11 +40,17 @@ def print_digest(self, start_date, stop_date):
for e in events:
name = e.location() if self.field == 'location' else e.title()
+
+ event_duration = e.endDate().timeIntervalSinceDate_(e.startDate()) / 3600.0
+
+ if event_duration_limit:
+ if event_duration >= event_duration_limit:
+ continue
if not name in projects:
projects[name] = 0.0
- projects[name] += e.endDate().timeIntervalSinceDate_(e.startDate())
+ projects[name] += event_duration
total = 0.0
@@ -56,11 +62,11 @@ def print_digest(self, start_date, stop_date):
if not p:
p = ''
- print p.ljust(20, ' '), "%0.2f" % (s / 3600.0)
+ print p.ljust(20, ' '), "%0.2f" % (s)
total += s
print "-" * 30
- print "Total".ljust(20, ' '), "%0.2f" % (total / 3600.0)
+ print "Total".ljust(20, ' '), "%0.2f" % (total)
print "-" * 30
def get_start_and_end_for_week(self, year, week):
@@ -120,7 +126,8 @@ def get_start_and_end_for_month(self, parser, options):
help="Number of the month until which to report (default: current)")
parser.add_option("-w", action="store_true", dest="week", metavar="WEEK",
help="Report for the current week")
-
+ parser.add_option("-s", action="store", type="int", dest="event_duration_limit", metavar="NUMBER",
+ help="Skip items which are longer than this number of hours")
parser.add_option("-l", action="store_true", dest="use_location",
help="Look for projects in events locations (default: titles)")
@@ -130,7 +137,7 @@ def get_start_and_end_for_month(self, parser, options):
group = OptionGroup(parser, "Example", "$ icalreport -c MyHours -m 9 -u 10 -l")
parser.add_option_group(group)
- group = OptionGroup(parser, "Example", "$ icalreport -c MyHours -w")
+ group = OptionGroup(parser, "Example", "$ icalreport -c MyHours -w -s 8")
parser.add_option_group(group)
(options, args) = parser.parse_args()
@@ -148,6 +155,11 @@ def get_start_and_end_for_month(self, parser, options):
ct = CalReport(cal_name=parser.values.cal_name, field=field)
+ if parser.values.event_duration_limit:
+ event_duration_limit = int(parser.values.event_duration_limit)
+ else:
+ event_duration_limit = 0
+
if options.week == True:
now = datetime.datetime.now()
@@ -158,4 +170,4 @@ def get_start_and_end_for_month(self, parser, options):
else:
start_date, stop_date = ct.get_start_and_end_for_month(parser, options)
- ct.print_digest(start_date, stop_date)
+ ct.print_digest(start_date, stop_date, event_duration_limit)

0 comments on commit d934142

Please sign in to comment.