Created
April 3, 2022 00:57
-
-
Save dwillis/625dfebb4b41e21f77f191cf698d68da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import csv | |
from dateutil.parser import parse | |
from slack import WebClient | |
from slack.errors import SlackApiError | |
slack_token = os.environ["SLACK_API_TOKEN"] | |
client = WebClient(token=slack_token) | |
march_27 = parse('3/27/2022').date() | |
breach_report = open('breach_report.csv', 'r').read() | |
csv_obj = csv.DictReader(breach_report) | |
breaches_to_process = [b for b in csv_obj if parse(b['Breach Submission Date']).date() >= march_27] | |
for b in breaches_to_process: | |
try: | |
response = client.chat_postMessage( | |
channel="slack-bots", | |
text=f"New breach submission: {b['Breach Submission Date']} by {b['Name of Covered Entity']}" | |
) | |
except SlackApiError as e: | |
# You will get a SlackApiError if "ok" is False | |
assert e.response["error"] # str like 'invalid_auth', 'channel_not_found' | |
# latest_breach = open('breach_report', 'w') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment