Using Tropo & Python to Have the Phone Tell Us the Weather

Posted 01 January 2013 - 03:38 AM

Alright well I decided to make a tutorial. In this tutorial we'll set up an automatic phone system, and, using Python, design it to answer the phone and tell you the weather in your area based on the zip code you give the program.

Step 1:

Set up an account on tropo. I'm assuming if you're reading this tutorial you have the computer savvy to set up an account on a website so I won't waste your time with that.

Step 2: Writing the Script

Now that you have your account all ready to use, log in and go to 'Your Hosted Files' and click 'Create New File.' (Note: It may be [much] easier to write out these files in your favorite Python writing program than to enter them directly onto tropo) Name the file what you want to and move down to the area named 'File Text'. First step is import the modules we need. After which we'll create a dictionary that we'll use later to convert the abbreviated days of the week to full names of the week and then a function that will do that work. Enter this. . .

This is pretty self explanatory. The function has a built in function which substitutes and returns the value that we want in the dictionary. Now we'll move on to my favorite part, which is scraping the web page.

This may be confusing at first glance but I assure you it isn't hard to understand. The first part that may look unfamiliar is the 'ask' command. That command is a built-in tropo command. The first option is the question that we're going to ask, the next three are pretty self-explanatory. Next, what we're doing is taking the xml document (urlRead), looking for a node called 'channel', then a node called 'item', then a node called 'yweather:forecast'. When we get to yweather:forecast we grab the day, low, high, and condition from it then use tropo's 'say' command to have our program output whatever we want it to.

At the bottom we call weather and then tell our phone to hangup once weather is done executing.

Step 3: Getting the phone number and testing it!

After entering all that, please don't forget to click save file or update file at the bottom of the text box you entered the code in! Ok, now that you have it saved, click on 'Your Applications'. Click 'Create New Application', name your app whatever you'd like to and click 'Hosted File' link and then click the 'Map existing file to this application' link. From there just select map next to the script we created in the last step. After that, click 'Create Application'.

Now you can use the numbers given or add your own and call up the number. If all goes as planned, it should work (I had to wait about 5 minutes for mine to become ready).