Improve Form Data Collection | Rapidly Build Cloud Infrastructure for Python Scripts Using WayScript
Articles,  Blog

Improve Form Data Collection | Rapidly Build Cloud Infrastructure for Python Scripts Using WayScript


Hello Everyone! In this tutorial let’s look at how we can
automate running a python script that’s connected to form. What we’ll do is we’ll create a form that
would trigger a python script and then send an email. Let’s take a look at a finished example first. This is the finished product of what will
be making in this tutorial. What we have is a contact form, and let’s
say we’re running an SEO Consulting business. We’re gathering information about how we
can help potential clients. We have a radio select for the role of our
potential client, we have a free text that we can put in a website, so we’ll just put
in mine. We have a selector for what the client selected
for what they need help with. And finally a user is able to put in their
email address at the bottom, so we can follow up with him. We’ll submit this and when they submit,
we can see on our back end that we created something that will run a python script to
go to that user’s website and get information about that website, so we don’t have to. Then we can send ourselves an email with the
information. Let’s go look at my email to see what we got. Checking out the email we see that we have
a new search engine ranking request from this website at the top and new request and where
to follow up with that client at. And then we’re just given a simple scrape
off their website. Of course we’re just running a python script
that’s connected to this form so you can customize this email however you want, but let’s see
how we can build this using WayScript. Go ahead and log in or sign up for WayScript
if you don’t already have an account, then will click on create a new script. We’ll say this one will be form to python
and click create. Click add trigger on add trigger and select
the form one, we can put in a title for whatever you want. I’ll stick with the same example “Consulting”
and put that in. We’ll put in a form description. So we’ll say something like, “how can we
help you with your SEO”? Next put in our questions so I had something
on my mine like select your role and this will be a selector and with a few options. we’ll do hobbyist, professional, and an
owner, add another form element. We’ll leave this one as a text input and
we’ll say “name of your website” and we’ll put in a placeholder of www.website.com. Add another question of how can we help you,
this one will be selector as well and we’ll put in a few options. Of course you can customize this form however
you like so don’t feel like you have to follow along completely. Add a “I want to learn more” and make
this a selector. Finally open in every text text input contact
email. We see that once we fill this out we get variables
down here at the bottom left. We can use these to trigger certain actions
within Wayscript. Let’s do this now. Click off of this and drag in an if statement
for a comparison. Let’s say if the form and output number for
so this is the one where we ask do you want more information. So if that is the same as yes, then we want
to follow up with that user. Now that we have that we need an action, so
let’s use Python to scrape their website so we can get that back in your email. Pulling up a python code module, clicking
on edit code to the left, and I’ll zoom in. WayScript has a bunch of libraries installed
and we can access those the same way we would in a python script. Since we’re using requests, let’s import that
as r. Now we can access this library and use it
throughout a python script. We can access this form and inputs. We can say something like potential website,
that our client has supplied, will be equal to the form input 4. so I’m dragging it in and dropping it here. Since we’re using python we can easily customize
it and use some data cleaning here. To make sure that we get to the website to
use our get requests, we need to supply HTTP on their website. So we need to check if the user has given
that to us and if not added. we will say something like if HTTP and potential
website so meaning that the user has supplied it will say full potential website is equal
to potential website then if they haven’t will say an else statement and put full potential
website is equal to the string HTTP and then concatenate the potential website. Of course there might be more data cleaning
here that you want to do, I just want to show you that it’s possible using WayScript. Next we need to send a request to this website. We’ll drop down and say response is equal
to our get request and then we’ll pass in full potential website. We’ll say print response dot Text. Now we can pass a variable to the rest of
WayScript work Flow by using this variables dictionary. We named this full website response and I’ll
just call it the same thing. Website is equal to the value in Python script
of full potential website. We’ll click done editing and now finally
we’ll construct the email that we will send ourselves. Click off of that and we’ll drag in our
send email module. We’ll make our subject line something like
input 3. So new advertising request and then we drag
in the website at the end of our title. So input to now will say something like role
is lobbyist and their contact email will be the input 5. We don’t have anything here yet because we
haven’t filled out the form, but we will in the future. And then we can put website and then drag
in what they specify as their website name. So let’s click off of that and close those. Now should I choose ‘YES’, we’ll collect
data and runs all of your Integrations automatically on the cloud. Let’s test it out by clicking on form trigger
and your form will give us a URL that we can access and give to other people right here. We’ll fill this out the same way, we’ll
click on some of it and we get a form submitted. Let’s go back to our script and we see that
our form submitted and our if statement return true because it found that I wanted more information. It went and scraped the website and sent it
to me as an email. I hope you see the power in this Cloud integration
that wayscript supplies. if you have any questions, as always please
let us know and we’ll get back to you. If you have any suggestions on what we should
build next please let us know that too. Until next time!

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *