Conduct Sentiment Analysis using Tweets (Serverless)

Jose Martinez
Analytics Vidhya
Published in
4 min readAug 9, 2020

Photo by Fay Fernandes on Unsplash

Before I started the Project

As for why I chose to partake in this project, I wanted to be able to expand my knowledge on the resources, libraries, and software available to me as an aspiring data analyst. In doing so, I was able to get some hands-on experience using numerous AWS services, working with APIs, making a website from scratch using HTML/CSS , and using JavaScript to enhance the site.

At the moment Twitter is arguably at the forefront for how millions of people receive their news. As a result, we can rely on that data to identify trends or to uncover breaking new stories and in turn allows for individuals/companies to make more informed decisions. By leveraging this resource brands can increase their public outlook by fixing or cutting their losses on a product that has poor sentiment. Furthermore, they’ll be able to better their interactions with customers around the globe.

Here’s how I envisioned the flow of the project would go before I did any coding or anything like that. The user will interact with the website by entering a keyword. The website would then access the API once the user submits the search. Then the API endpoint will call the Python function, and the python script will input some JSON data to the S3 bucket so that it can be stored. This tool was created using a free resource called ZenUML, which allows you to make Sequence diagrams using code.

Making a Mockup of Website

When deciding what I wanted the website to look like I had to ask myself what is the bare minimum that the website needs? Well I need to have a place for the user to search, a submit button to submit the search, and table to display the data. In addition to those three components I figured it would be important to have links to the code and blog posts, and in the future I would include a place for visualizations and a spot to showcase a video or GIF of me making the web app. The tool used to make this mockup is a free tool called Moqups.

Making the Website

Now that I had an idea of what my site was going to look like I created two files, index.html and style.css. The index file will hold the content of the page including the javascript code while the style file will simply format the webpage.

This code in this <form> tag is the main foundation seeing that it allows the website to interact with Javascript. In short the user will enter the keyword in the search and once they click the submit button the Javascript code will be called to run the loadData() function.

The const base_url takes the base API url which won’t return anything since it has a NULL value. This is where we extract the search that was submitted and append it to the base_url. To invoke the API_url you must do a request. In my case since I am using a GET method I have “request.open(‘GET’, API_URL, true)”, but if I wanted to do a POST method you would simply replace it with the GET.

To wrap up the Javascript code I have to parse the JSON data that is taken from API endpoint, and this is done so within the data const. Now it’s just a matter of iterating through the parsed response by using a for loop and populating the database. After each iteration the “table.innerHTML += row” ensures that the data is added to the table before it begins iterating the next JSON object.

Closing Remarks

I hope you enjoyed my blog post. I am Jose Martinez, recent UMD Graduate (Dec’19) looking to start my career in Data Analytics. If you’d like to check out some more of my work feel free to checkout my Github Website with my resume, Github projects, and the code from this Blog. This is my first blog post so it would be great if you’d leave a comment with some feedback, fill out this Contact form or reach out to me on Twitter or LinkedIn. Stay tuned for my next blog post where I’ll dive into setting up the AWS Lambda script, connecting to the Twitter API, and much more.

Source Code

--

--

Jose Martinez
Analytics Vidhya

Recent grad with a bachelor’s degree in Information Sciences. Aspiring to apply strong analytical, research, and technical skills to the Data Analytics field.