Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

A lab to get you started with the Weather and Twitter services

License

Notifications You must be signed in to change notification settings

IBM-Cloud/places-insights-lab

Repository files navigation

Places Insights Hands on Labs

⚠️ DEPRECATED This sample used the now retired Insights for Twitter service. Source code is kept as reference only.

Places Insights provides weather observation and related tweets for famous places to visit. It uses the Insights for Twitter and Weather Company Data services in IBM Bluemix. The lab will guide you through deploying your own instance of the application in IBM Bluemix and modifying the code to retrieve data from the two services.

Let's get started. The first thing to do is to build out the shell of our application in Bluemix.

Command-line aficionados, if you want to, we got you covered with this other set of instructions.

Creating a IBM Bluemix account

  1. Sign up for IBM Bluemix at the registration page if you don't already have a IBM Bluemix account.

  2. Log in your IBM Bluemix account.

Test the application

Now that we have deployed our application to IBM Bluemix, the next step is to test out the application in its current state. Afterwards we will build out more functionality into the application.

  1. Go to the IBM Bluemix Dashboard by selecting "Dashboard" from the header bar.

  2. Select the application you just created under Applications.

  3. Click the first link near Routes at the top of the screen. This takes you to your application.

Routes

This application proposes a list of places across the globe. Once you will have completed this lab, it will update the display with the current weather, a 10 day forecast for the selected location and a list of tweets referring to this place.

Application with no data

The application uses Node.JS for the backend, AngularJS for the user interface and two IBM Bluemix services:

  • The Weather Company Data for IBM Bluemix service provides weather observation and forecast for a specified geolocation (and a lot more).
  • The Insights for Twitter service provides access to Twitter Decahose (10% of Twitter data) and Twitter PowerTrack (100% of Twitter data) together with sentiment analysis and social enrichments.

Modify the existing application

Now that you have the basics running it is time to add more functionality to this application, mainly retrieving weather and tweets for the selected location.

  1. Let's edit our source code. Back on the application overview page in IBM Bluemix, you will see a link to the Jazz Hub repository, and a button to Edit Code. Click on Edit Code

Go to Edit

  1. Clicking on Edit Code will take you to the Jazz Hub repository, which will allow us to edit and push new versions of our code to the application.

  2. With the repository, navigate to public/js/app.js and open that file to view the application source code

Edit

  1. Locate the comment Retrieve current weather. The implementation of the function currently returns an empty object. Comment the line returning the empty object and uncomment the actual code calling the server API. Note that the implementation calls an API on the backend, passing the latitude and longitude of a location.

  2. Repeat the same operation for the comment Retrieve 10 day forecast. The code to uncomment will call the backend API to get weather forecast.

  3. Repeat the same operation for the comment Retrieve tweets for location. The code to uncomment will call the backend API to get some tweets about the location.

  4. Click on File > Save or press Ctrl+S

Deploy

  1. The last step in order to complete our application is to deploy our changes to IBM Bluemix. To do this, we need to push our new code to the application. In the code editor screen, switch to the Git Repository view - the 2nd icon in the left navigation bar.

Git

  1. Locate your changes to app.js file. Check it (select it), add a commit message and click Commit

Commit

  1. Click Sync to send your changes from this workspace to the main repository and trigger a deploy of your app.

Sync

  1. Finally, click on Build & Deploy to see the deploy process.

Build and Deploy

Test

To test our changes, navigate back to the application screen on IBM Bluemix and select your application route. The "Build & Deploy" may take few minutes to complete. During that time you may see a message like 404 Not Found: Requested route ('myapp.mybluemix.net') does not exist. when accessing your application.

In the new version of the application, you will be able to view the current weather, the weather forecast and tweets for the selected place.

Application showing Weather and Twitter data

Behind the scene

When the user selects a place, the function updateInsights in public/js/app.js is called. This function will trigger the right API calls to retrieve Weather and Twitter data.

the call to retrieve... is implemeted in public/js/app.js as... on the backend, in lib/server.js it is received by... and delegated to... finally when the response comes back, it is rendered by
Current weather WeatherService#current #api_weatherCurrent lib/weather.js #currentByGeolocation weather.html
10 day forecast WeatherService#forecast #api_weatherForecast lib/weather.js #tendayByGeolocation weather.html
Tweets TwitterService#tweets #api_tweets lib/twitter.js #search twitter.html

Weather Company Data for IBM Bluemix API

Opening lib/weather.js, you can find the implementation of the calls to the Weather Company Data for IBM Bluemix service. The service REST APIs can be found here.

All operations used in this lab take a geolocation as input together with a language for the messages being returned (for example, en-US, es, es-MX, fr-FR) and units of measure for the data (for example, e=Imperial(English), m=Metric, h=Hybrid).

Insights for Twitter API

The calls to the Insights for Twitter service are implemented in lib/twitter.js. The service has two sets of REST APIs:

  • one to query Twitter Decahose (10% of Twitter) - this is the one used in our application Insights for Twitter Decahose API
  • and one to query Twitter PowerTrack (100% of Twitter) Insights for Twitter PowerTrack API

Congratulations

You have completed the lab!

Want to go further?

Here are some suggestions to improve the application:

  • Update the Twitter for Insights query to return only the tweets from the 30 days or even make it a parameter of the user interface
  • Insights for Twitter and Insights for Weather API allow querying language-specific data. Improve the application by automatically detecting the user language or providing a language selector to display weather data and tweets in the selected language.
  • Retrieve and display hourly forecast from the Insights for Weather service
  • Use a map instead of hardcoded locations.

Credits

About

A lab to get you started with the Weather and Twitter services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published