-
Notifications
You must be signed in to change notification settings - Fork 23
/
announce_orga_birthdays.py
executable file
·44 lines (28 loc) · 1.13 KB
/
announce_orga_birthdays.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
"""Wish orgas a happy birthday.
Meant to be called by a daily cronjob or similar mechanism.
:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""
import click
from byceps.announce.helpers import call_webhook
from byceps.services.orga import birthday_service
from byceps.services.webhooks import service as webhook_service
from byceps.services.webhooks.transfer.models import OutgoingWebhook, WebhookID
from _util import app_context
def validate_webhook_id(ctx, param, webhook_id: WebhookID) -> OutgoingWebhook:
webhook = webhook_service.find_webhook(webhook_id)
if webhook is None:
raise click.BadParameter(f'Unknown webhook ID "{webhook_id}".')
return webhook
@click.command()
@click.argument('webhook', callback=validate_webhook_id)
def execute(webhook: OutgoingWebhook):
users = birthday_service.get_orgas_with_birthday_today()
for user in users:
text = f'Happy Birthday, {user.screen_name}!'
call_webhook(webhook, text)
click.secho('Done.', fg='green')
if __name__ == '__main__':
with app_context():
execute()