diff --git a/mongodb/roles/mongod/tasks/main.yml b/mongodb/roles/mongod/tasks/main.yml
index 3a2135d..4bf30a3 100644
--- a/mongodb/roles/mongod/tasks/main.yml
+++ b/mongodb/roles/mongod/tasks/main.yml
@@ -33,3 +33,8 @@
sudo: yes
service: name=mongod state=started
+- name: Create the tweet sentiment collection
+ shell: mongo tweets --eval "db.createCollection('sentiment')
+
+- name: Create the sentiment geospatial index
+ shell: mongo tweets --eval 'db.sentiment.createIndex({ coordinates: "2dsphere" })'
diff --git a/rest/.idea/workspace.xml b/rest/.idea/workspace.xml
index 5367619..cecd40a 100644
--- a/rest/.idea/workspace.xml
+++ b/rest/.idea/workspace.xml
@@ -5,15 +5,11 @@
-
-
-
-
-
-
+
-
-
+
+
+
@@ -27,8 +23,8 @@
-
-
+
+
@@ -43,6 +39,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -83,8 +91,8 @@
-
-
+
+
@@ -92,11 +100,21 @@
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -104,11 +122,21 @@
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -132,7 +160,6 @@
@@ -177,8 +205,8 @@
DEFINITION_ORDER
-
-
+
+
@@ -222,70 +250,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -306,7 +272,7 @@
-
+
@@ -620,7 +586,7 @@
-
+
@@ -646,23 +612,23 @@
-
-
+
+
-
+
-
+
-
+
@@ -708,13 +674,9 @@
-
-
- file://$PROJECT_DIR$/../twitter/sentimentConsumer.py
- 42
-
-
-
+
+
+
@@ -722,7 +684,7 @@
-
+
@@ -750,7 +712,7 @@
-
+
@@ -807,16 +769,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -942,14 +894,6 @@
-
-
-
-
-
-
-
-
@@ -998,14 +942,6 @@
-
-
-
-
-
-
-
-
@@ -1014,14 +950,6 @@
-
-
-
-
-
-
-
-
@@ -1051,16 +979,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1081,30 +999,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rest/rest.py b/rest/application.py
similarity index 94%
rename from rest/rest.py
rename to rest/application.py
index 1960a29..f46401b 100644
--- a/rest/rest.py
+++ b/rest/application.py
@@ -2,6 +2,7 @@
from flask_restful import Resource, Api
import unittest
import json
+from pymongo import MongoClient
"""
@@ -12,7 +13,7 @@
longitude
radius (meters)
- GET http://localhost:5000/sentiment?lat=40.7128N?lon=74.0059W?radius=5000
+ GET http://localhost:5000/sentiment?lat=40.7128?lon=74.0059?radius=5000
The response is a JSON object with the following structure
@@ -52,8 +53,8 @@ def get(self):
api.add_resource(Sentiment, '/')
# run the app server
-# if __name__ == '__main__':
-# app.run(debug=True)
+if __name__ == '__main__':
+ app.run(debug=True)
"""
@@ -104,5 +105,5 @@ def test_bad_path(self):
# Run the unit tests
-if __name__ == '__main__':
- unittest.main()
+#if __name__ == '__main__':
+# unittest.main()
diff --git a/rest/requirements.txt b/rest/requirements.txt
new file mode 100644
index 0000000..a6ef560
--- /dev/null
+++ b/rest/requirements.txt
@@ -0,0 +1,38 @@
+aniso8601==1.1.0
+awsebcli==3.7.7
+blessed==1.9.5
+botocore==1.4.48
+cement==2.8.2
+click==6.6
+colorama==0.3.7
+docker-py==1.7.2
+dockerpty==0.4.1
+docopt==0.6.2
+docutils==0.12
+Flask==0.11.1
+Flask-RESTful==0.3.5
+itsdangerous==0.24
+Jinja2==2.8
+jmespath==0.9.0
+kafka==1.3.1
+MarkupSafe==0.23
+nltk==3.2.1
+oauthlib==1.1.2
+pathspec==0.3.4
+pymongo==3.3.0
+python-dateutil==2.5.3
+pytz==2016.6.1
+PyYAML==3.11
+redis==2.10.5
+requests==2.9.1
+requests-oauthlib==0.6.2
+rq==0.6.0
+semantic-version==2.5.0
+six==1.10.0
+termcolor==1.1.0
+textblob==0.11.1
+texttable==0.8.4
+tweepy==3.5.0
+wcwidth==0.1.7
+websocket-client==0.37.0
+Werkzeug==0.11.10
diff --git a/twitter/sentimentConsumer.py b/twitter/sentimentConsumer.py
index 1e01d79..ed7d299 100644
--- a/twitter/sentimentConsumer.py
+++ b/twitter/sentimentConsumer.py
@@ -51,7 +51,7 @@
for message in consumer:
try:
- job = q.enqueue(process_tweet, args=(message, args.mongohost, args.mongoport, 'tweets'))
+ job = q.enqueue(process_tweet, args=(message.value, args.mongohost, args.mongoport, 'tweets'))
except KeyboardInterrupt:
consumer.close()
diff --git a/twitter/sentiments/sentimentProcessor.py b/twitter/sentiments/sentimentProcessor.py
index bb191eb..49ee580 100644
--- a/twitter/sentiments/sentimentProcessor.py
+++ b/twitter/sentiments/sentimentProcessor.py
@@ -3,9 +3,10 @@
def process_tweet(tweet, host, port, db):
+ print ('processing...')
if 'text' in tweet:
print 'processing...'
- mongo_client = MongoClient(host=host, port=port, db=db)
+ mongo_client = MongoClient(host=host, port=port)
mongodb = mongo_client[db]
tweet_text_blob = TextBlob(tweet['text'])
result = dict(text=tweet['text'],
diff --git a/twitter/twitter_utils/twitterStreamListener.py b/twitter/twitter_utils/twitterStreamListener.py
index dc32f56..24298da 100644
--- a/twitter/twitter_utils/twitterStreamListener.py
+++ b/twitter/twitter_utils/twitterStreamListener.py
@@ -28,8 +28,9 @@ def on_data(self, data):
if not self.caughtInterrupt:
tweet = json.loads(data)
if self.geo_only and 'coordinates' in tweet and tweet['lang'] == 'en':
- self.serializer.write(tweet)
- return True
+ if tweet['coordinates'] is not None:
+ self.serializer.write(tweet)
+ return True
else:
self.serializer.end()
return False