catch exceptions from scrapper

This commit is contained in:
Maciej Ścigacz 2023-05-30 13:57:44 +02:00
parent 9e48b92d3e
commit 3394f00690
2 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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():
try:
url = request.get_json()
result = scrapp_comments(url['link'])
result['status'] = True
return result
except:
return jsonify({'status':False})