This is a Python app that uses the Bottle framework and the following services:
- MongoDB (backend database)
The source for this app is at GitHub so, for example, if you are using the command line you can clone the repository like this:
git clone https://github.com/ibmjstart/bluemix-python-sample-twitter-influence-app.git
This app uses some external APIs. You need to register the app with Twitter and Klout to get the keys and tokens for the wsgi.py file.
To access the Twitter API you need the consumer keys and access tokens, so you must register the app with Twitter. You can register your app here.
More information on how to register the app with Twitter
You can register the app with Klout here. When you register with Klout, you'll get a Klout Key, which you can use to create a Klout Object as shown in the code.
This app uses the Google Maps v3 APIs. Google APIs are open for the developers and you do not need to register the app with Google. Here's the link for the Google Maps APIs.
Screen-shot of the wsgi.py file that shows where the Twitter keys and access tokens and Klout developer key is entered:
After including the Twitter/Klout keys and tokens in the wsgi.py file (as shown above), you are ready to deploy the app. In the terminal, go in the directory of the app (where wsgi.py is located). Multiple methods exist for interacting with the BlueMix platform. Outlined below is one of those methods:
Before we begin, we first need to install the cf command line tool that will be used to upload and manage your application. If you've previously installed an older version of the cf tool, make sure you are now using v6 of cf by passing it the -v flag:
cf -v
In the terminal, go to the directory of the app, and follow these steps.
-
Login to Bluemix.
usage: $ cf login [-a API_URL] [-o ORG] [-s SPACE]
example: $ cf login -a https://api.ng.bluemix.net
-
Create an instance of the MongoDB service, giving it a unique name in the last arguement.
usage: $ cf create-service SERVICE PLAN SERVICE_INSTANCE
example: $ cf create-service mongodb 100 mongodb_PTIA
-
From the directory that houses the wsgi.py file, push the app with the --no-start option so we can bind our required service before starting. Pass the -c flag to specify the start command that should be used by CloudFoundry to run your app. Pass the -b flag to specify the Python build pack to be used, https://github.com/joshuamckenty/heroku-buildpack-python is recommended. Be sure to give your app a unique app name to be used as its host; for example, the example below would result in https://nmu.ng.bluemix.net.
usage: $ cf push APP [--no-manifest] [--no-start] [-c COMMAND]
example: $ cf push ptia --no-manifest --no-start -b https://github.com/joshuamckenty/heroku-buildpack-python -c "python ./wsgi.py"
-
Bind the MongoDB service instance to the new app
usage: $ cf bind-service APP SERVICE_INSTANCE
example: $ cf bind-service ptia mongodb_PTIA
-
Start the app
usage: $ cf start APP
example: $ cf start ptia
If your Python app requires any external dependencies (i.e. any modules that you install using 'pip install'), you need to include them in the requirements.txt file. Each module must be downloaded and put in the directory of the app (e.g. app), and the relative path to that module must be included in the requirements.txt file.
You should not need to do this to deploy this app because the dependencies are already included in the requirements.txt file, and the external modules are also included in the root directory of the app. While deploying the app, the requirements.txt file should be detected and automatically install the dependencies.
This is the home screen of the app. You can enter a twitter screen name in the text box and click the Analyze button to see their influence. You can also view any records saved in the database by clicking on the 'View Database' button.
After entering the twitter name and clicking the Analyze button, you'll be able to see the influence analysis of that person on the left side. You will also see their last 10 tweets and any recent mentions in the tweets plotted on Google Maps (if there is geolocation data for a tweet).
These are the records of the Influencers in the database. The user can export the records as csv file. There is also a feature to send the records in csv format to any person via email using the SMTP service, if the SMTP service is not bound to the application you can not do this and the features will be disabled.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.