def persistTweet(tweet): tweeter = TwitterHandler() json_msg = json.loads(tweet['Message']) tid = json_msg['id'] location_data = json_msg['location'] message = json_msg['message'] author = json_msg['author'] timestamp = json_msg['timestamp'] sentiment = json_msg['sentiment'] response = tweeter.insertTweet(tid, location_data, message, author, timestamp, sentiment) # print response return response
def persistTweet(tweet): print "Tweet received by persister: ", tweet tweeter = TwitterHandler() json_msg = json.loads(tweet['Message']) tid = json_msg['id'] location_data = json_msg['location'] message = json_msg['message'] author = json_msg['author'] timestamp = json_msg['timestamp'] sentiment = json_msg['sentiment'] anger = json_msg['anger'] joy = json_msg['joy'] sadness = json_msg['sadness'] fear = json_msg['fear'] disgust = json_msg['disgust'] response = tweeter.insertTweet(tid, location_data, message, author, timestamp, sentiment, anger, joy, sadness, fear, disgust) # print response return response
def parse_data(data): json_data_file = json.loads(data) tweetHandler = TwitterHandler() location = json_data_file["place"] coordinates = json_data_file["coordinates"] if coordinates is not None: # print(json_data_file["coordinates"]) final_longitude = json_data_file["coordinates"][0] final_latitude = json_data_file["coordinates"][0] elif location is not None: coord_array = json_data_file["place"]["bounding_box"]["coordinates"][0] longitude = 0 latitude = 0 for object in coord_array: # print(object) longitude = longitude + object[0] latitude = latitude + object[1] # print(longitude / len(coord_array)) # print(latitude / len(coord_array)) final_longitude = longitude / len(coord_array) final_latitude = latitude / len(coord_array) tweetId = json_data_file['id_str'] tweet = json_data_file["text"] author = json_data_file["user"]["name"] timestamp = json_data_file["created_at"] location_data = [final_longitude, final_latitude] try: print( tweetHandler.insertTweet(tweetId, location_data, tweet, author, timestamp)) except: print("Failed to insert tweet")
def searchKeywordWithDistance(keyword, distance, latitude, longitude): searchTweets = TwitterHandler() result = searchTweets.getTweetsWithDistance(keyword, distance, latitude, longitude) return jsonify(result)
def searchKeyword(keyword): searchTweets = TwitterHandler() result = searchTweets.getTweets(keyword) return jsonify(result)