From 03c29ac6639f8df3ec130fb77b6818390cb8dcde Mon Sep 17 00:00:00 2001 From: liangxianzhe Date: Tue, 23 Feb 2021 16:40:22 -0800 Subject: [PATCH 1/2] Support print csv format --- pull_alerts.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/pull_alerts.py b/pull_alerts.py index d426c54..32e9a2c 100644 --- a/pull_alerts.py +++ b/pull_alerts.py @@ -24,7 +24,7 @@ class FormattedIncident(object): - def pretty_output(self): + def _pretty_output(self): return u'Time: {}\nService: {}\nDescription: {}\nURL: {}\nNotes:\n{}\n'.format( self.created_on.strftime('%A, %B %-d - %-I:%M %p'), self.service, @@ -33,6 +33,20 @@ def pretty_output(self): self.notes, ) + def _csv_output(self): + return u'{},{},{},{},"{}"'.format( + self.created_on.strftime('%A, %B %-d - %-I:%M %p'), + self.service, + self.description, + self.url, + self.notes, + ) + + def output(self, print_csv): + if print_csv: + return self._csv_output() + else: + return self._pretty_output() def recent_incidents_for_services(services, time_window): service_ids = [service.id for service in services] @@ -48,6 +62,7 @@ def print_all_incidents( time_window_days, group_by_description=False, group_by_service=False, + print_csv=False, include_stats=False, include_incidents_as_blockquote=False, ): @@ -74,13 +89,14 @@ def print_all_incidents( sorted_group_to_incident_list = sorted_description_to_incident_list if group_by_service or group_by_description: for group, incident_list in sorted_group_to_incident_list.iteritems(): - print("########### {}: {} ##########\n".format(len(incident_list), group)) + if not print_csv: + print("########### {}: {} ##########\n".format(len(incident_list), group)) if not silent: for incident in incident_list: - print(incident.pretty_output()) + print(incident.output(print_csv)) else: for incident in all_incidents: - print(incident.pretty_output()) + print(incident.output(print_csv)) print('Total Pages: {}'.format(len(all_incidents))) if include_incidents_as_blockquote: @@ -187,6 +203,10 @@ def is_non_actionable(incident): action="store_true", default=False, help="Group PD incidents by service") + parser.add_argument("--print-csv", + action="store_true", + default=False, + help="Print in CSV format") parser.add_argument("--include-stats", action="store_true", default=False, @@ -204,7 +224,8 @@ def is_non_actionable(incident): silent=args.silent, group_by_description=args.group_by_description, group_by_service=args.group_by_service, + print_csv=args.print_csv, include_stats=args.include_stats, include_incidents_as_blockquote=args.include_incidents_as_blockquote, time_window_days=args.days - ) + ) \ No newline at end of file From 503f374da15f9563755075e076ef56b7dd797b6a Mon Sep 17 00:00:00 2001 From: rajagubba <98428444+rajagubba@users.noreply.github.com> Date: Wed, 7 Sep 2022 14:13:48 -0500 Subject: [PATCH 2/2] Upgrade python-dateutil version for py3.9 support (#33) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7148172..214a361 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ pygerduty==0.38.3 -python-dateutil==2.4.2 +python-dateutil==2.8.2