This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving CLI functions to a discoverable location (#257)
- Loading branch information
Showing
35 changed files
with
232 additions
and
221 deletions.
There are no files selected for viewing
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
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
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import blueprints | ||
|
||
events_bp = blueprints.Blueprint("events", __name__) | ||
|
||
from . import cli # noqa isort:skip |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
|
||
import click | ||
|
||
from .blueprint import events_bp | ||
from .sync_database import sync_database_with_fetched_events | ||
from .upcoming_events import generate_upcoming_events_message | ||
from busy_beaver.clients import SlackClient | ||
from busy_beaver.models import SlackInstallation | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@click.option("--count", default=5, required=True, help="Number of events to post") | ||
@click.option("--group_name", required=True, help="Meetup group name") | ||
@click.option("--channel", required=True, help="Slack channel") | ||
@click.option("--workspace", required=True, help="Slack workspace ID") | ||
@events_bp.cli.command( | ||
"post_upcoming_events", help="Post Upcoming Events Summary to Slack channel" | ||
) | ||
def post_upcoming_events_message_to_slack_cli( | ||
workspace: str, channel: str, group_name: str, count: int | ||
): | ||
blocks = generate_upcoming_events_message(group_name, count) | ||
installation = SlackInstallation.query.filter_by(workspace_id=workspace).first() | ||
slack = SlackClient(installation.bot_access_token) | ||
slack.post_message(blocks=blocks, channel=channel) | ||
|
||
|
||
@click.option("--group_name", required=True, help="Meetup group name") | ||
@events_bp.cli.command("sync_events_database", help="Sync Events Database") | ||
def sync_events_database_cli(group_name: str): | ||
sync_database_with_fetched_events(group_name) |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
...ng_events/event_database/sync_database.py → busy_beaver/apps/events/sync_database.py
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from datetime import timedelta | ||
import logging | ||
|
||
import click | ||
|
||
from .blueprint import github_bp | ||
from .summary.workflow import fetch_github_summary_post_to_slack | ||
from busy_beaver.exceptions import ValidationError | ||
from busy_beaver.models import SlackInstallation | ||
from busy_beaver.toolbox import utc_now_minus | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@click.option("--workspace", required=True, prompt="Slack workspace ID") | ||
@github_bp.cli.command("post_github_summary", help="Post a GitHub summary") | ||
def post_github_summary_to_slack_cli(workspace: str): | ||
boundary_dt = utc_now_minus(timedelta(days=1)) | ||
installation = SlackInstallation.query.filter_by(workspace_id=workspace).first() | ||
if not installation: | ||
raise ValidationError("workspace not found") | ||
|
||
# we should log that we did something somewhere | ||
# also keep track of how long a summary took | ||
# TODO once we are migrated over | ||
fetch_github_summary_post_to_slack(installation, boundary_dt) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
from . import task # noqa | ||
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
import random | ||
from typing import List | ||
|
||
from sqlalchemy import and_ | ||
|
||
from .blocks import GitHubSummaryPost | ||
from busy_beaver.common.wrappers import SlackClient | ||
from busy_beaver.models import GitHubSummaryUser | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def fetch_github_summary_post_to_slack(installation, boundary_dt): | ||
channel = installation.github_summary_config.channel | ||
slack = SlackClient(installation.bot_access_token) | ||
|
||
channel_members = slack.get_channel_members(channel) | ||
users: List[GitHubSummaryUser] = GitHubSummaryUser.query.filter( | ||
and_( | ||
GitHubSummaryUser.config_id == installation.github_summary_config.id, | ||
GitHubSummaryUser.slack_id.in_(channel_members), | ||
GitHubSummaryUser.github_username.isnot(None), | ||
) | ||
).all() | ||
random.shuffle(users) | ||
|
||
github_summary_post = GitHubSummaryPost(users, boundary_dt) | ||
github_summary_post.create() | ||
|
||
slack.post_message( | ||
blocks=github_summary_post.as_blocks(), | ||
channel=channel, | ||
unfurl_links=False, | ||
unfurl_media=False, | ||
) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import logging | ||
|
||
import click | ||
|
||
from .blueprint import twitter_bp | ||
from .workflow import fetch_tweets_post_to_slack | ||
from busy_beaver.config import TWITTER_USERNAME | ||
from busy_beaver.models import SlackInstallation | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@click.option("--channel_name", required=True, help="Slack channel") | ||
@click.option("--workspace", required=True, help="Slack workspace ID") | ||
@twitter_bp.cli.command("poll_twitter", help="Find new tweets to post to Slack") | ||
def poll_twitter(channel_name: str, workspace: str): | ||
# TODO add logging and times | ||
installation = SlackInstallation.query.filter_by(workspace_id=workspace).first() | ||
fetch_tweets_post_to_slack(installation, channel_name, username=TWITTER_USERNAME) |
Oops, something went wrong.