SMS Bot Using Python and Twilio

I built the SMS bot using the Twilio API and Python, which allows you to send a Twilio number messages and get answers back. I got the inspiration of this project and some part of the codes from Make webpage. For this work I used Twilio API, Ngrok, Flask, Wolfram Alpha API, Wikipedia, and yWeather.

Steps:

1. Install ngrok and add the exec file in Mac:

/usr/local/bin

2. Go to twilio webpage (https://www.twilio.com/)and get free API and number (number should have sms capability)
3. Install ngrok and add the exe file here (open /usr/local/bin)
4. You need to get API from Wolfram Alpha (https://products.wolframalpha.com/api/) and add that API to getReply.py line 43.
5. Run run.py
6. Type in terminal (same path as run.py)

ngrok http port_number

You will see on you screen:

Version                                                            
Region                                                    
Web Interface                                              
Forwarding                           
Forwarding 

copy one of the Forwarding address (something like http:// …. .io)

7. Go to your Twilio dashboard and press the “#” on the left. Click on your Twilio number, scroll down and enter the http address into the space that says “A message comes in” in Messaging part. Make sure the dropdown is set to “webhook”. Now paste the Forwarding address here!
8. Open sms app on your mobile and type your question and send in to your Twilio number. (e.g., wiki Barak Obama )
9. Thanks to Sophia Smith and me, now you have working SMS chatbot 🙂

Continue reading

Distance between two GPS coordinates

For distance between two GPS coordinates as I googled I realized the best method to use is haversine formula.

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical “triangles”.

Continue reading

Generating a Google Static Maps API with markers

Go

The Google Static Maps API lets you embed a Google Maps image on your web page without requiring JavaScript or any dynamic page loading. The Google Static Maps API service creates your map based on URL parameters sent through a standard HTTP request and returns the map as an image you can display on your web page.

The Google Static Maps API returns an image (either GIF, PNG or JPEG) in response to an HTTP request via a URL. For each request, you can specify the location of the map, the size of the image, the zoom level, the type of map, and the placement of optional markers at locations on the map. You can additionally label your markers using alphanumeric characters.

In this post I decided to write a function to generating a Google Static Maps with marker as easy as possible here is my version:

Continue reading

Cropping image

As all you know sometimes cropping image can be challenging. Some days ago I had some issues in cropping part of my training image. My problem was my region wasn’t rectangular, so here is my solution to non-rectangular region cropping. I hope in would be useful for us as well 🙂

Continue reading

Find simple shapes in an image

In this post I am going to solve this problem, how to find simple shapes like triangular and square ( or rectangular) in the image.  For simple shape like square or triangular I normally use this procedure:

1. Find Contours in the image ( image should be binary)
2. Approximate each contour using approxPolyDP function.
3. Check number of elements in the approximated contours of all the shapes to recognize the shape. For eg, triangular will have 3; for square or rectangle, it has to meet the following conditions:
* It is convex.
* It has 4 vertices.
* All angles are ~90 degree.
4. Assign the color, run the code for your test image, check its number, fill it with corresponding colors.

Assumptions: Shapes don’t overlap, both of them solid (meaning, there is no white pixels inside the shape (all shapes are black). There can be multiple shapes in the image and they can be rotated any arbitrary number of degrees, and they can be of any size. Important: Triangles are non-obtuse!

Continue reading