Introducing Autopilot, an AI coding assistant
gradient
How to write automation scripts

How to write automation scripts

Madhura Kumar
Head of Growth
Aug 15, 2022
5 min read

Automation scripts are automated pieces of code that run on a set schedule or a predefined condition. They can also be triggered manually when they require a specific user input.

For example, instead of manually tagging code reviewers on a pull request, you can write an automation script or use a tool like Airplane to send a list of open pull requests that need a code review to a Discord server at the start of each day.

Airplane is a developer platform for quickly transforming scripts, queries, and APIs into internal applications. If you're looking to quickly spin up internal tools and workflows, Airplane is a great option because it requires little-to-no setup and provides a number of enterprise-grade features out of the box like role-based access controls, schedules, conditional logic, input validation, audit logs, and more.

In this article we'll walk through how to write some common automations using Airplane such as: writing Python and JavaScript automation scripts, generating reports using SQL, syncing data between sources, and customer onboarding.

Python automation scripts

Using Airplane you can write code-based tasks such as Python tasks and Node.js tasks.

Let's start with a Python example since Python is one of the most frequently used languages for writing automation scripts.  Using Airplane, you can write and deploy Python-based tasks to convert functions into reusable apps for your team in just minutes.

See below for an example of a Python automation script. We can write a Python task that selects a code reviewer for the day and sends a Slack message with the required information. This can be represented by the following:

Python

The above code reads a JSON file that contains the GitHub usernames of the developers working at a company. Next, it chooses a random user from the list of choices and returns the selected user’s username.

You can take a Python script like the above or any other Python script and deploy it to Airplane using the Airplane CLI.

Once you've installed the CLI, run airplane init and follow these instructions which will allow you to deploy your task to Airplane in a few seconds.

You can find more information on deploying Python-based tasks in the documentation.

JavaScript automation scripts

Similar to the example above where we used Python, we can write scheduled tasks in JavaScript. See below for a JavaScript code snippet that retrieves a list of open pull requests in a GitHub repository.

JavaScript

The above code uses GitHub’s JavaScript SDK and returns the title and url of all of the open pull requests in the specified GitHub repository.

We can create and deploy this task to Airplane the same way we did our Python task:

You can find more information on deploying JavaScript-based tasks in the documentation.

Generating reports using a SQL query

One of the simplest but most common automations is report generation. You can use weekly or quarterly reports for many purposes including tracking performance metrics, monitoring for slow queries, and surfacing flagged transactions.

Let's walk through a quick example of how to use Airplane to generate a report of flagged/suspicious transactions. You can use Airplane to create a three-step reporting workflow that might look something like the below:

  1. First, we use a SQL query to look up flagged transactions
  2. Then, we use Python-based task to generate a fraud report
  3. Finally, a Slack notification is sent with the report to the designated Slack channel using Airplane's Slack integration
You can use Airplane to automate a three-step reporting workflow that might look something like this image.

Using Airplane, you can write a script and run it on a recurring basis to not only generate a report, but also to send the report to key stakeholders via email or Slack as described in the example above. Using Airplane's native Slack integration, you can easily configure approval flows, send reminders, and paste outputs directly into Slack channels.

To learn more about generating a recurring report with SQL, you can check out this 5-min tutorial.

Syncing data between data sources

Software applications use data that is often collected from multiple sources. For example, some team members may be using Google Sheets, some may be working with Typeform forms, and others may be using traditional data-management sources like MySQL databases.

Most of the time we want this data to live in a single source of truth with only point of access. In order to implement a single source of truth, we have to sync the data between our various data sources. This is another common automation and one that's very easy to solve using Airplane.

A really quick way to solve for this is write a script in Airplane that adds the data from Google Sheets to your production MySQL database or any other non-relational database, depending on the kind of application you're building.

If you're looking to write to a SQL database with Node, you can check out this quick 5-min tutorial on using Node.js and node-postgres to write a task to make an update to a PostgreSQL database.

Customer onboarding

Customer onboarding is one of the most common and useful automations engineers implement within their organizations. Depending on the company, some onboarding steps can be extremely time-consuming and require escalation to the engineering team. Take Dover, a B2B SaaS recruiting platform, for example. In order to onboard new customers they have to go through a series of operations:

  1. Import historical data from the customer's applicant tracking systems
  2. Integrate Dover with the customer's email accounts
  3. Collect data about the role the customer is recruiting for
  4. Send notifications when accounts have been provisioned
  5. Answer support questions during the onboarding process
  6. and much more

Dover uses Airplane to run a set of synchronous scripts to accomplish these tasks after specifying the relevant inputs, like the unique customer ID. Another simple example of a customer onboarding workflow in Airplane might look something like:

  1. Create an account by running a SLQ query
  2. Send the user an email for verification using Airplane's email integration
  3. Verify the user's default payment method using the Stripe API which you can hit using an Airplane task

You can read more about how Dover uses Airplane as their complete internal tooling solution in this case study.

Build sophisticated automations easily with Airplane

In this article we discussed some simple but common automation examples and how to easily implement them using Airplane. These example only scratch the surface of what Airplane can be used for within an organization.

While the example we discussed were simple, Airplane can be used to to build out sophisticated internal applications with a broad set of use cases including workflow automation, scheduled operations, admin panels and user management, long-running jobs, custom full-featured UIs and much more.

If you found anything in this post interesting, sign up for a free Airplane account to try it out or say hello at [email protected].

Share this article:
Madhura Kumar
Head of Growth
Madhura Kumar is the Head of Growth and a founding team member at Airplane. Prior to Airplane, she led product and strategic initiatives at Palantir.

Subscribe to new blog posts from Airplane.