Anant example-cassandra-alpakka-twitter
License: No License Provided
Language: Scala
This project is a Scala application which uses Alpakka Cassandra 2.0, Akka Streams and Twitter4S (Scala Twitter Client) to pull new Tweets from Twitter for a given hashtag (or set of hashtags) using Twitter API v1.1 and write them into a local Cassandra database.
NOTE: The project will only save tweets which are not a retweet of another tweet and currently only saves the truncated version of tweets (<=140 chars).
docker run -p 9042:9042 --rm --name my-cassandra -d cassandra
docker ps -a
The above output shows that the container has been running for 3 minutes, and also shows that port 9042 locally is bound to port 9042 in the container. (default port for Cassandra)
docker exec -it my-cassandra cqlsh
CREATE KEYSPACE testkeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
CREATE table testkeyspace.testtable(id bigint PRIMARY KEY, excerpt text);
INSERT INTO testkeyspace.testtable(id, excerpt)
VALUES (37, 'appletest');
exit
application.conf.example
file found in /src/main/resources/application.conf.example
. Copy this file into this same directory and rename it application.conf
mv /src/main/resources/application.conf.example /src/main/resources/application.conf
application.conf
:twitter {
consumer {
key = "consumer-key-here"
secret = "consumer-secret-here"
}
access {
key = "access-key-here"
secret = "access-token-here"
}
}
/src/main/scala/com/alptwitter/AlpakkaTwitter.scala
and change the following line to indicate what hashtags you wish to look at new tweets for val trackedWords = Seq("#myHashtag")
:vim /workspace/example-cassandra-alpakka-twitter/src/main/scala/com/alptwitter/AlpakkaTwitter.scala
If you want to track more than one hashtag, add more by adding more strings and separating with commas.
sbt run
As new tweets are posted which contain any of the hashtags listed in the trackedWords variable, a message will print in the console which says whether the tweet was a retweet or a unique tweet.
docker exec -it my-cassandra cqlsh
SELECT * FROM testkeyspace.testtable;
Join Our Newsletter!
Sign up below to receive email updates and see what's going on with our company.