changing notifications on scraper

This commit is contained in:
Catalina Syddall
2019-07-16 18:11:19 -03:00
parent 2302fea3d1
commit ca4e17c852
3 changed files with 16 additions and 32 deletions
+14 -18
View File
@@ -29,20 +29,9 @@ payload = {
def slack_notification(text, scraper, status=Status.Error):
"""Post Slack notification"""
if status == Status.Error:
emoji = ":thumbsdown: "
title = "data_scraper error"
color = "#B22222"
else:
title = "data_scraper status report"
if status == Status.Success:
emoji = ":thumbsup: "
color = "#49C39E"
else:
emoji = ":warning: "
color = "#EDB625"
msg = emoji + text
title = "data_scraper status report"
color="#ff9906"
msg = text
payload["attachments"][0]["fallback"] = msg
payload["attachments"][0]["text"] = msg
@@ -65,13 +54,20 @@ def send_report(done, failed, scraper, op="scrape"):
`failed` is a list of symbol names that could not be scraped/aggregated
"""
if done > 0:
msg = "Successfully {}d {}".format(op, _symbol_str(done))
slack_notification(msg, scraper, status=Status.Success)
msg1 = "Successfully {}d {}".format(op, _symbol_str(done))
if len(failed) > 0:
msg = "Failed to {} {}: {}".format(op, _symbol_str(len(failed)),
msg2 = "Failed to {} {}: {}".format(op, _symbol_str(len(failed)),
", ".join(failed))
slack_notification(msg, scraper, status=Status.Warning)
msg= msg1 + " and " + msg2
slack_notification(msg, scraper, status=Status.Warning)
def _symbol_str(count):
return str(count) + " symbol" if count == 1 else str(count) + " symbols"
## make init + make env ##
##cambiar el channel
##sacar notificaciones por cada error y armar un mensaje combinando todo
##python
##