Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion WEB/controllers/tweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def load_tweets():
return json.dumps({'Exception': str(ex)}), 500, JSON_CONTENT_TYPE

@app.route('/tweets', methods=['POST'])
def getTweets():
def searchTweets():
'''
Retrieve tweets from the database based on provided search criteria.
---
Expand Down Expand Up @@ -58,3 +58,20 @@ def getTweets():
search_text = body.get('search')
tweets = tweets_service.get_tweets_from_db(search_text)
return tweets, 200, JSON_CONTENT_TYPE

@app.route('/tweets', methods=['GET'])
def getTweets():
'''
Retrieve all tweets from the database. Largely for testing purposes.
---
produces:
application/json
responses:
200:
description: Successfully retrieved the tweets
examples:
application/json: {"statuses": [{"created_at": "Sun Mar 31 18:32:35 +0000 2019","id": 1112422454528524300...example tweet elided}]}
500:
description: Server error occurred
'''
return tweets_service.get_tweets_from_db(), 200, JSON_CONTENT_TYPE
2 changes: 1 addition & 1 deletion WEB/services/tweets_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_tweets_from_twitter():
tweets_response = requests.get('https://api.twitter.com/1.1/search/tweets.json', params=tweet_search_params, headers=tweet_headers)
return tweets_response.json()

def get_tweets_from_db(search_text):
def get_tweets_from_db(search_text = None):
mongo = database_service.get_mongo_client()
matching_tweets = mongo.db.tweets.find(format_db_search(search_text))
return dumps(list(matching_tweets))
Expand Down