Skip to content

Commit

Permalink
there's a better way to do this which has its own ticket (#498) but i…
Browse files Browse the repository at this point in the history
…n the meantime redvic and amsterdam are extraneous locations for slack hooks.
  • Loading branch information
jessykate authored and jonathan-s committed Mar 11, 2019
1 parent 1385c98 commit 69916b9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 76 deletions.
2 changes: 0 additions & 2 deletions core/management/commands/run_daily_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def handle(self, *args, **kwargs):
tasks.send_guest_welcome()
tasks.send_departure_email()
tasks.slack_embassysf_daily()
tasks.slack_ams_daily()
tasks.slack_redvic_daily()
gather_tasks.events_today_reminder()
if datetime.date.today().weekday() == 6: # sunday
gather_tasks.weekly_upcoming_events()
Expand Down
74 changes: 0 additions & 74 deletions core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,77 +132,3 @@ def slack_embassysf_daily():
logger.debug("Slack response: %s" % resp.text)


@catch_exceptions
def slack_ams_daily():
''' post daily arrivals and departures to slack. to enable, add an incoming
web hook to the specific channel you want this to post to. grab the webhook
url and put it in the webhook variable below.'''
if not settings.ENABLE_SLACK:
logger.info("Skipping task: slack_ams_daily")
return

logger.info("Running task: slack_ams_daily")
webhook = "https://hooks.slack.com/services/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"
today = timezone.localtime(timezone.now())
location = Location.objects.get(slug="amsterdam")
arriving_today = Use.objects.filter(location=location).filter(arrive=today).filter(status='confirmed')
departing_today = Use.objects.filter(location=location).filter(depart=today).filter(status='confirmed')

payload = {
'text': 'Arrivals and Departures for %s' % today.strftime("%B %d, %Y"),
'attachments': []
}
for a in arriving_today:
item = _format_attachment(a, "good")
payload['attachments'].append(item)
for d in departing_today:
item = _format_attachment(d, "danger")
payload['attachments'].append(item)
if len(arriving_today) == 0 and len(departing_today) == 0:
payload['attachments'].append({
'fallback': 'No arrivals or departures today',
'text': 'No arrivals or departures today'
})

js = json.dumps(payload)
logger.debug(js)
resp = requests.post(webhook, data=js)
logger.debug("Slack response: %s" % resp.text)


@catch_exceptions
def slack_redvic_daily():
''' post daily arrivals and departures to slack. to enable, add an incoming
web hook to the specific channel you want this to post to. grab the webhook
url and put it in the webhook variable below.'''
if not settings.ENABLE_SLACK:
logger.info("Skipping task: slack_redvic_daily")
return

logger.info("Running task: slack_redvic_daily")
webhook = "https://hooks.slack.com/services/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"
today = timezone.localtime(timezone.now())
location = Location.objects.get(slug="redvic")
arriving_today = Use.objects.filter(location=location).filter(arrive=today).filter(status='confirmed')
departing_today = Use.objects.filter(location=location).filter(depart=today).filter(status='confirmed')

payload = {
'text': 'Arrivals and Departures for %s' % today.strftime("%B %d, %Y"),
'attachments': []
}
for a in arriving_today:
item = _format_attachment(a, "good")
payload['attachments'].append(item)
for d in departing_today:
item = _format_attachment(d, "danger")
payload['attachments'].append(item)
if len(arriving_today) == 0 and len(departing_today) == 0:
payload['attachments'].append({
'fallback': 'No arrivals or departures today',
'text': 'No arrivals or departures today'
})

js = json.dumps(payload)
logger.debug(js)
resp = requests.post(webhook, data=js)
logger.debug("Slack response: %s" % resp.text)

0 comments on commit 69916b9

Please sign in to comment.