Introduction
Connecting mySQL, python, and airtable has never been this easy to do. In this example using WayScript, let's walk through ho we can pull information from a mySQL database, process it using python programming, and then input that data into our Airtable database.
Prerequisites
No prerequisites but some content you might find helpful:
Working with databases
Working with CRON
Working with Airtable
Working with Python
Activating a Script Routinely
To activate any script on WayScript at set intervals, on certain days, or at certain time, we offer the use of the time trigger:
We're able to do anything fancy that you might want to using full CRON syntax to denote when we want to activate our script.
For the purposes of simplicity, let's make our's run everyday.
Once we have this, anything contained in this tree will be executed, everyday, at 7AM.
Connecting our Database
To connect our database, we'll need to drag it into our workflow below our time trigger.
Once here, we'll need to provide some information for WayScript to be able to read/write your database. If you need help with setting up your database, our documentation has a full video and text walkthrough. As with anything else, if you get stuck feel free to reach out to us on our discord as well.
Using a Date time module
If we want to pass today's date to airtable each time we execute our script, we can use the date time module.
This gives us access to a variable in our variables panel that we can pass to airtable later on.
Executing your Database Action
Now that we have the database in the workflow, we're able to write SQL statements and execute those against our tables just like how we would locally. Click edit code to the left:
This will give us access to the text editor, in which we can write our own custom code. Let's just put something simple in:
SELECT SUM(score) from survey;
This will give us back the query value as a variable we can use throughout the rest of our script.
Processing with Python
To process the data that we pull from airtable with python, we can pull in a python module below the SQL module.
From here we can edit the code and write something like this:
sum_a = variables['Column_0']
print(sum_a)
sum_b = int(sum_a)*2
print(sum_b)
variables[ 'sum_b' ] = sum_b
We're just doing a bare bones processing operation here of multiplying our value by two, but this step could be much more depending on your requirements.
Passing to Airtable
Once the variable is passed back from the python module, we can input it into airtable. Drag an airtable module below this python step and then configure the settings:
We're writing the values that we created throughout the steps to our airtable, using the create a new record mode.
Questions, Need Help?
If you have any questions, comment below or feel free to message us on Discord. We're happy to help! If you want to see this full script template, you can find it here.
Top comments (0)