I made an python code that fetch tweets from Mongo collection called Tweets. I wan't to fetch only the object text and add an additional object called Sentiment.
When i loop through the Tweets and parse the json object to a string i get the error :
from pymongo.objectid import ObjectId ImportError: No module named objectid
Therefor i use the following code
import pymongo
import nltk
import json
from json import JSONEncoder
from pymongo import MongoClient
from pymongo.objectid import ObjectId
#JSON Encoder
class MongoEncoder(JSONEncoder):
def default(self, obj, **kwargs):
if isinstance(obj, ObjectId):
return str(obj)
else:
return JSONEncoder.default(obj, **kwargs)
#Mongo Settings
client = MongoClient()
db = client.Sentiment
Tweets = db.Tweet
TweetTraining = db.TweetTraining
#GET TEXT_TAG FROM TWEET
for tweet in Tweets.find({"lang":"nl"},{"text"}):
print json.dumps(tweet, cls=MongoEncoder)
I hope that you can help me out. Many thanks
Erik