Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

ksatirli/twitter-sentiment-analysis-with-terraform

Repository files navigation

Twitter Sentiment Analysis

Easily analyze (emotional) sentiment of Tweets using Google Cloud and HashiCorp Terraform

Table of Contents

Requirements

  • Terraform CLI 1.0.9 or newer
  • a Google Cloud account
  • a Twitter App token

Usage

This repository contains Terraform Resources to deploy a Google Workflow for Twitter Sentiment Analysis.

To use this code, clone the repository and initialize Terraform:

cd twitter-sentiment-analysis-with-terraform

terraform init

The init command will fetch all required Terraform Providers.

Next, execute a plan:

terraform plan

Note: The code is set up to use GCP Organization IDs. If your setup requires Folder IDs, change maint.tf and variables.tf in the appropriate locations.

If the preview looks good, you can deploy the resources using the apply command:

terraform apply

When Terraform finishes the apply process, several Outputs will be displayed.

These Outputs contain URLs for the Google Cloud Console:

Outputs:

url_project_settings         = "console.cloud.google.com/iam-admin/settings"
url_service_account_detail   = "console.cloud.google.com/iam-admin/serviceaccounts/details"
url_service_account_overview = "console.cloud.google.com/iam-admin/serviceaccounts"
url_workflow_details         = "console.cloud.google.com/workflows/workflow/us-central1/twitter-sentiment/executions"
url_workflow_execution       = "console.cloud.google.com/workflows/workflow/us-central1/twitter-sentiment/create_execution"
url_workflows_overview       = "console.cloud.google.com/workflows"

Note: The URLs will be specific to your account and will include Organization and Project IDs.

Find the Output with key url_workflow_execution and open the generated URL in a browser to display the Workflow Execution interface:

Execute Google Workflow

In this interface, add the following configuration as Input:

{
  "bearerToken": "AAA...2Ho",
  "twitterHandle": "ksatirli",
  "maxResults": "100"
}

Modify the Input payload to reflect your situation:

  • Replace the value of bearerToken with an active Twitter App Bearer Token.
  • Replace the value of twitterHandle with a relevant Twitter Handle.
  • Adjust the value of maxResults, keeping in mind that the allowed range is 10 to 100.

Next, execute the Workflow by clicking the blue EXECUTE button at the bottom.

After the Workflow has completed, the Output will display the calculated values:

{
  "averageSentiment": 0.25,
  "minSentimentIndex": 2,
  "minSentimentScore": -0.1,
  "numberOfTweets": 5,
  "totalSentimentScore": 1.5
}

Notes

Author Information

This repository is maintained by the contributors listed on GitHub.

License

Licensed under the Apache License, Version 2.0 (the "License").

You may obtain a copy of the License at 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.