/civictechto-scripts

Helper scripts for CivicTechTO organizing tasks

Primary LanguagePython

CivicTechTO Scripts

Run scripts CircleCI Status

Helper scripts for CivicTechTO organizing tasks.

We use this as a catch-all for simple scripts that help with organizing tasks. Many of them run automatically each week.

Contents

Trigger Description Script 🔗 Docs Status 🔗 Logs
Nightly Update shortlinks from gsheet gsheet2shortlinks.py Logs: Update Shortlinks
Day Before Announce roles in #organizing-open notify_slack_roles.py Logs: Notify Slack Roles
Pre-Hacknight Reset Trello pitch column move_trello_cards.py Logs: Reset Pitches
Post-Hacknight Save pitch info to dataset update_pitch_csv.py Logs: Save Pitch Data
Save Pitch Data Announce pitches in #general notify_slack_pitches.py Logs: Notify Slack Pitches

About these Automated Scripts

Some of these scripts are automatically run before and after hacknight, using CircleCI's workflow feature. (Update: A migration from CircleCI to GitHub Actions is in progress.) The schedule is set in the .circleci/config.yml file within this repo.

Here's a diagram showing how project pitch information flows into, through and out of the Trello board, in part via scripts:

(Click to see expanded view.)
Process Flow Diagram

Technologies Used

💻 Local Development

These scripts are designed to run in the cloud, using code from the master branch on GitHub. However, they can also be run on a local workstation. Further, contributions should be tested locally before pushing changes to repo, as changes to existing scripts on master will then come into effect.

Setup

We recommend using pipenv for isolating your Python environment. After installing, just follow these steps.

  1. Install the required packages:

    # Run this only first-time or after pulling git changes.
    $ pipenv install
    # Run this at the start of each terminal session.
    $ pipenv shell
  2. Copy the configuration file:

    $ cp sample.env .env
    
  3. Edit the file according to its comments. (Some scripts can take command-line args directly.)

Scripts

move_trello_cards.py

On the Trello board, this moves all cards from one list to another.

eg. Tonight's Pitches ➡️ Recently Pitched

Runs pre-hacknight.

$ pipenv run python move_trello_cards.py --help

Usage: move_trello_cards.py [OPTIONS]

Options:
  -k, --api-key TEXT     Trello API key.  [required]
  -s, --api-secret TEXT  Trello API token/secret.  [required]
  -f, --from-list TEXT   Name or ID of Trello list which cards are moved FROM.
                         [required]
  -t, --to-list TEXT     Name or ID of Trello list which cards are moved INTO.
                         [required]
  -b, --board TEXT       ID of Trello board on which to act.  [required]
  -d, --older-than DAYS  If provided, card only moved if older than this.
                         Default: 0
  -y, --yes              Skip confirmation prompts
  -v, --verbose          Show output for each action
  -d, --debug            Show full debug output
  --noop                 Skip API calls that change/destroy data
  -h, --help             Show this message and exit.

update_pitch_csv.py

This updates the historical dataset of breakout groups who pitched each week, based on the Trello board.

Runs post-hacknight.

notify_slack_pitches.py

This takes data from the Trello board, and drops a message in Slack's #general channel, announcing who pitched this week.

Runs post-hacknight.

Screenshot of Slack post

notify_slack_roles.py

This takes data from the Hacknight Roles spreadsheet, and drops a message in Slack's #organizing-open channel, announcing who signed up for each hacknight-organizing role this month. If a role is unclaimed, it solicits help.

Runs day before hacknight.

Screenshot of Slack post

gsheet2meetup.py

This takes data from a GDrive spreadsheet (sample), and uses it to create/update events in a Meetup.com group. It uses a simple template format, populated by spreadsheet columns, for the event description (sample).

$ python scripts/gsheet2meetup.py --help

Usage: gsheet2meetup.py [OPTIONS]

  Create/update events of a Meetup.com group from a Google Docs spreadsheet.

Options:
  --gsheet <url>            URL to publicly readable Google Spreadsheet,
                                including sheet ID gid  [required]
  --meetup-api-key <string>     API key for member of leadership team
                                [required]
  --meetup-group-slug <string>  Meetup group name from URL  [required]
  -y, --yes                     Skip confirmation prompt
  -d, --debug                   Show full debug output
  --noop                        Skip API calls that change/destroy data
  -h, --help                    Show this message and exit.

Runs nightly at 4am ET.

gsheet2shortlinks.py

This takes data from a GDrive spreadsheet (sample), and uses it to create/update shortlinks managed on Rebrandly.

$ python gsheet2shortlinks.py --help

Usage: gsheet2shortlinks.py [OPTIONS]

  Create/update Rebrandly shortlinks from a Google Docs spreadsheet.

  Here are some notes on spreadsheet columns:

      * slashtag: the shortlink component of path.

      * destination_url: where the shortlink points to.

      * If the following columns exist and a --google-creds option is
      passed, they will be updated:

          * Note: These features are not yet implemented.

          * created: date and time when the link was created and tracking
          began.

          * clicks: number of click-through since creation.

      * Extra columns will have no effect.

Options:
  --gsheet <url>                  URL to publicly readable Google Spreadsheet,
                                  including sheet ID gid  [required]
  --rebrandly-api-key <string>    API key for Rebrandly  [required]
  -d, --domain-name <example.com>
                                  Shortlink domain on Rebrandly  [required if
                                  multiple domains on account]
  -y, --yes                       Skip confirmation prompts
  -d, --debug                     Show full debug output
  --noop                          Skip API calls that change/destroy data
  -h, --help                      Show this message and exit.

Runs nightly at 4am ET.

upload2gdrive command

This command uploads local files to a Google Drive folder.

$ pipenv run python cli.py upload2gdrive --help

Usage: cli.py upload2gdrive [OPTIONS] FILE

Options:
  -f, --gdrive-folder <url/id>  Google Drive folder to upload file into. (URL
                                or folder ID)  [required]
  -c, --google-creds <file>     JSON keyfile for a Google service account.
                                [required]
  -y, --yes                     Skip confirmation prompts
  -v, --verbose                 Show output for each action
  -d, --debug                   Show full debug output
  --noop                        Skip API calls that change/destroy data
  -h, --help                    Show this message and exit.

This command runs in conjunction with other tasks/scripts.

next-meetup command

$ pipenv run python cli.py next-meetup --help

Usage: cli.py next-meetup [OPTIONS]

  Get the next event for a given Meetup group.

  * Can be filtered based on event title. * Can echo any event fields from
  the Meetup API response.

Options:
  --meetup-api-key <string>     API key for member of leadership team
                                [required]
  --meetup-group-slug <string>  Meetup group name from URL  [required]
  --filter <string|regex>       String or pattern to match on event title, for
                                seeking next event. Case-insensitive. Default:
                                None.
  --fields <one,two>            Comma-separated list of event fields to
                                return. Default: event_url
  -y, --yes                     Skip confirmation prompts
  -v, --verbose                 Show output for each action
  -d, --debug                   Show full debug output
  --noop                        Skip API calls that change/destroy data
  -h, --help                    Show this message and exit.

This command runs in conjunction with other tasks/scripts.

announce-booking-status command

Reads from the speaker booking spreadsheet and generates a message in Slack.

Screenshot of posted Slack message

$ pipenv run python cli.py announce-booking-status --help

Usage: cli.py announce-booking-status [OPTIONS]

  Notify a slack channel of high-level status for upcoming event & speaker
  booking.

Options:
  --gsheet TEXT       URL to publicly readable Google Spreadsheet.  [required]
  --slack-token TEXT  API token for any Slack user.
  -c, --channel TEXT  Name or ID of Slack channel in which to announce.
                      [required]
  -y, --yes           Skip confirmation prompts
  -v, --verbose       Show output for each action
  -d, --debug         Show full debug output
  --noop              Skip API calls that change/destroy data
  -h, --help          Show this message and exit.

This command runs weekly after hacknight.

update-member-roster command

Updates a spreadsheet (example) from membership in a Slack channel (in our case, the invite-only #organizing-priv). This spreadsheet is in turn intended to be used to render a view of those members on a webpage, etc. (Related: CivicTechTO/people-list-parser)

Screenshot of spreadsheet and rendered grid

$ pipenv run python cli.py update-member-roster --help
Usage: cli.py update-member-roster [OPTIONS]

  Update a spreadsheet of members based on Slack channel membership.

Options:
  --gsheet TEXT       URL to publicly readable Google Spreadsheet.
[required]
  --slack-token TEXT  API token for any Slack user.
  -c, --channel TEXT  Name or ID of Slack channel in which to fetch
                      membership.  [required]
  -y, --yes           Skip confirmation prompts
  -v, --verbose       Show output for each action
  -d, --debug         Show full debug output
  --noop              Skip API calls that change/destroy data
  -h, --help          Show this message and exit.

Note: Runs nightly.

send_monthly_project_email.py

This take data from the historical dataset of breakout groups (generated via update_pitch_csv.py), and sends out a MailChimp update once/month, using this MailChimp template.

This is a work in progress, and doesn't yet work or run regularly.

list_dm_partners.py

$ pipenv run python list_dm_partners.py --help

Usage: list_dm_partners.py [OPTIONS]

  Generates a list of DM conversation partners.

  * Generates a list based on private and group DM's.

  * For ease, the list itself is DM'd to the user account for whom the Slack
  token was generated.

      * NONE of the mentioned users will be notified of this first message,
      since it occurs in the DM.

      * This list of usernames can be copied into new messages and modified
      to suit needs.

Options:
  --slack-token TEXT  API token for any Slack user.
  -h, --help          Show this message and exit.

This script doesn't run automatically. It is intended to be run from a local computer.

Screenshot of Slack DM