-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding in the redis cache queuing and sentiment analyzers
- Loading branch information
1 parent
0f68f1f
commit 248b217
Showing
10 changed files
with
373 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
tickTime=2000 | ||
dataDir=/var/lib/zookeeper | ||
clientPort=2181 | ||
clientPort=2181 | ||
admin.enableServer=true | ||
clientPortAddress=0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/python | ||
|
||
import argparse | ||
import json | ||
from kafka import KafkaConsumer | ||
from redis import Redis | ||
from rq import Queue | ||
from sentiments.sentimentProcessor import process_tweet | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Attach to the twitter stream API and send the tweets to a destination', | ||
add_help=True, | ||
formatter_class=argparse.RawDescriptionHelpFormatter) | ||
|
||
parser.add_argument('--kafkahost', | ||
type=str, | ||
required=False, | ||
help='The host name of the Kafka broker if using Kafka serialization') | ||
parser.add_argument('--kafkaport', | ||
type=int, | ||
required=False, | ||
help='The port of the Kafka broker if using Kafka serialization') | ||
parser.add_argument('--mongohost', | ||
type=str, | ||
required=False, | ||
help='The host name of the mongoDB server') | ||
parser.add_argument('--mongoport', | ||
type=int, | ||
required=False, | ||
help='The port number of the mongoDB server') | ||
parser.add_argument('--redishost', | ||
type=str, | ||
required=False, | ||
help='The host name of the Redis cache') | ||
parser.add_argument('--redisport', | ||
type=int, | ||
required=False, | ||
help='The port of the Redis Cache') | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
kafka_server = "{0}:{1}".format(args.kafkahost, args.kafkaport) | ||
|
||
redis_conn = Redis(host=args.redishost, port=args.redisport) | ||
q = Queue(connection=redis_conn) | ||
|
||
consumer = KafkaConsumer('tweets', | ||
value_deserializer=lambda m: json.loads(m.decode('utf-8')), | ||
bootstrap_servers=[kafka_server]) | ||
|
||
for message in consumer: | ||
try: | ||
job = q.enqueue(process_tweet, args=(message, args.mongohost, args.mongoport, 'tweets')) | ||
|
||
except KeyboardInterrupt: | ||
consumer.close() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from textblob import TextBlob | ||
from pymongo import MongoClient | ||
|
||
|
||
def process_tweet(tweet, host, port, db): | ||
if 'text' in tweet: | ||
print 'processing...' | ||
mongo_client = MongoClient(host=host, port=port, db=db) | ||
mongodb = mongo_client[db] | ||
tweet_text_blob = TextBlob(tweet['text']) | ||
result = dict(text=tweet['text'], | ||
coordinates=tweet['coordinates'], | ||
polarity=tweet_text_blob.polarity, | ||
subjectivity=tweet_text_blob.subjectivity) | ||
|
||
mongodb.sentiment.save(result) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters