DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Top 10 Pillars of Zero Trust Networks
  • How To Integrate the Stripe Payment Gateway Into a React Native Application
  • Deploying Smart Contract on Ethereum Blockchain
  • Unlocking Game Development: A Review of ‘Learning C# By Developing Games With Unity'

Trending

  • Top 10 Pillars of Zero Trust Networks
  • How To Integrate the Stripe Payment Gateway Into a React Native Application
  • Deploying Smart Contract on Ethereum Blockchain
  • Unlocking Game Development: A Review of ‘Learning C# By Developing Games With Unity'
  1. DZone
  2. Data Engineering
  3. Data
  4. Building A Smart Twitter Bot with Apache NiFi

Building A Smart Twitter Bot with Apache NiFi

This article gives a simple tutorial on how to build your first Twitter bot with ease using Apache NiFi. Read on to find out more.

Tim Spann user avatar by
Tim Spann
CORE ·
May. 11, 18 · Tutorial
Like (4)
Save
Tweet
Share
9.11K Views

Join the DZone community and get the full member experience.

Join For Free

Let's start with a few images.

This is the new processor, PutTwitterProcessor, it will use Twitter4J to send tweets from a parameter you set.

This is an example tweet and my reply to it. It's a regular tweet.

This is the result of a run. I put the tweet id and date-time stamp in the result attribute.

Another example:

You need to create a Twitter application and obtain the Consumer Key, Consumer Secret, Access Token, and Access secret. If you have a lat and long in your data, you can send that. It's optional. The message takes expression language and lets you build a message.

JUnit Test of My Processor

JUnit Run Results

Most of the code is using the very easy to use Twitter4J library.

So, what can I do with this? In my flow, I am ingesting Tweets, and with a streaming SQL query, I can retweet ones where there is no existing retweet, and the followers of the tweet are more than 1,000. I can also feed all of this information to a Hive table and then run some machine learning on it to figure out other parameters to filter on for my bot.

This is a start. I put a scheduler on my PutTweet to only tweet every 10 minutes (600 seconds). Let's see how this goes.

SQL for QueryRecord

SELECT * FROM FLOWFILE WHERE CAST(retweet_count AS DOUBLE) <= 0 AND CAST(followers_count AS DOUBLE) > 1000



Example Message Building

${'user_name':append( ' '):append( ${'location'} ):append(' '):append(${'hashtags'} ):append(' ' ):append(${'msg'})}


Download NAR to Install in Apache NiFi lib Directory and Then Restart:

https://github.com/tspannhw/nifi-puttwitter-processor/releases/tag/1.0

Apache NiFi Twitter bot twitter

Opinions expressed by DZone contributors are their own.

Trending

  • Top 10 Pillars of Zero Trust Networks
  • How To Integrate the Stripe Payment Gateway Into a React Native Application
  • Deploying Smart Contract on Ethereum Blockchain
  • Unlocking Game Development: A Review of ‘Learning C# By Developing Games With Unity'

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: