The Force Is Strong With This One

So, we are almost at the end of the journey here and I am so excited to do so. In my previous post, I demonstrated how to pick up the pieces from the returned data and put them into a single file. That was easy right?

The problem is that if someone else wanted to use my code, they would have to change parts of the code every time, which is not very smart! Today, I am going to put our code together, encapsulate it in a function that will take one parameter from the user and perform the tricks behind the scenes and boom, you get clean tweets containing the query keyword you entered. I know, I should stop talking and show you what I did:


I hope you are able to read that piece of code. You can also click on the image to view a clearer version of it. Now, all you need to do to see the results is pass in a value to the prompt and then the code will do its job for you. Think of a word, answer the prompt and see what is happening on twitter. I thought of  ‘ellen’, ‘obama’, and 2013: Here is what I got in that order:


So, after running three tests, I had what you see above and it obviously look like a lot of tweets or sentences but with a few formatting tricks, you could make them look pretty easy to read! Again, just click on that image for a better view!

Go ahead and run the code, add some styling and see what happens.

So, in just a few steps, we have gone from typing into our browsers a url that returned a bunch of messy data from Twitter servers, to digging into the data and retrieving important pieces, and now, we have taken the bold move of making our code more useful – anyone can run it, with any keyword and still get results.

I hope this was helpful to you and if you have any questions, please do not hesitate to ask me through the comments section. Let us connect, we can learn a lot from each other!

Thanks for visiting and please remember to subscribe for updates!

Written By Elisha Chirchir

Elisha Chirchir is a software developer. He is also the founder of Simple Developer and co-founder of Instinctive Software Solutions. On any given day, he works on both Android and Web Development. During his 'free time', he offers training to those interested in learning how to code in php, java, python, javaScript etc. You can easily find him on StackOverflow Android chatroom or on Twitter @Eenvincible

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.