catch exceptions from scrapper
This commit is contained in:
parent
9e48b92d3e
commit
3394f00690
@ -14,6 +14,7 @@ def sentiment_prediction(data):
|
||||
|
||||
def clear_data(data):
|
||||
data = [re.sub(r"[^A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ ']+", r"", i) for i in data['sentences']]
|
||||
data = [x for x in data if x != '']
|
||||
data = [i.strip() for i in data]
|
||||
data = [i.lower() for i in data]
|
||||
return data
|
||||
@ -46,5 +47,5 @@ def scrapp_comments(url):
|
||||
for comment in post['comments_full']:
|
||||
comments.append(comment['comment_text'])
|
||||
all['post'] = text_post
|
||||
all['comments'] = comments
|
||||
all['sentences'] = comments
|
||||
return all
|
||||
|
@ -10,7 +10,8 @@ sentiment_service = Blueprint("sentiment_service", __name__)
|
||||
@sentiment_service.route("/get_sentiment_data", methods=['POST'])
|
||||
def get_data():
|
||||
data = request.get_json()
|
||||
data_clear = clear_data(data) #czyszczenie danych wejsciowych
|
||||
data_clear = clear_data(data)
|
||||
print(data_clear) #czyszczenie danych wejsciowych
|
||||
predicitons = sentiment_prediction(data_clear) #predykcje
|
||||
count_labels = count_predictions(predicitons) #dane do wykresu
|
||||
|
||||
@ -23,6 +24,10 @@ def get_data():
|
||||
|
||||
@sentiment_service.route("/scrapp_comments", methods=['POST'])
|
||||
def scrapp():
|
||||
url = request.get_json()
|
||||
result = scrapp_comments(url['link'])
|
||||
return result
|
||||
try:
|
||||
url = request.get_json()
|
||||
result = scrapp_comments(url['link'])
|
||||
result['status'] = True
|
||||
return result
|
||||
except:
|
||||
return jsonify({'status':False})
|
Loading…
Reference in New Issue
Block a user