DEV Community

Derrick Sherrill
Derrick Sherrill

Posted on

Here's your new favorite Python Cloud Tool: Run Scripts in Minutes


From increasing productivity to minimizing data loss, running programs on the cloud comes with many advantages. With WayScript, you can run Python programs from the cloud and further customize them to carry out other functions.


For this tutorial, we will be using an example Python program that generates a random Game of Thrones GIF when run.

The script uses Giphy's API and can be found here.

The API is used through a third party library called Requests.

This is the program we will be running from the cloud:

import requests
from urllib.parse import urlencode
import json
from random import randint
search_term = 'game of thrones'
url = ''
params = { 'api_key' : 'k7MNLPnCM0qWlJBHIbGdoxLfZbK51Rvs',
                     'q'         :  search_term,
                     'lang'    :  'en' }
url += urlencode( params )
r = requests.get( url )
result = r.json()
i = randint( 0, len( result[ 'data' ] ) - 1 )
rand_result = result[ 'data' ][i]
url = rand_result[ 'images' ][ 'original' ][ 'url' ]
print( url )

Now that we have our Game of Thrones GIF generator program ready, we will create a new program on WayScript to run this program on the cloud. In addition, we will be making minor but useful modifications to the program. For example, we will have the random GIF emailed to us.

Step One - Input Your Program

Build a program from scratch and drag the Python module into to the first step of your program.

Paste your code into the module.

Step Two - Create Outputs

For our program to send us the email of the generated GIF, we're going to need to create a variable that contains the URL of the GIF. Instead of printing the URL, we're going to make it an output so that the URL can be used by other modules of our WayScript program.

I will replace the last line of code in the program with a line that stores the URL as an output.

As you can see, when the code is run, it now stores the URL as a variable to be used.

Step Three - Add An Email Module

Since we want the GIF emailed to us, we're going to add in the Gmail module to our recipe.

In the 'Inputs' section, we will be entering the content of our email. We can embed the GIF into the body of the email by using the image tag with the link of the GIF as our source.

Writing "[url]" as your image source will use the link contained in your url variable that you created before.

Step Four - Add A Trigger

You can also add a daily trigger to have the email sent to you daily at a certain time.

Step Five - Run Your Program

The program is now complete. Upon hitting 'Run Program', an email containing a random Game of Thrones GIF will be sent to the designated receiving address in the Gmail module.

Congratulations! You have successfully run a Python program from the cloud.

Top comments (0)