lalithadevi commited on
Commit
02dba55
1 Parent(s): 9e645b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -45,13 +45,21 @@ def update_news():
45
  new_news = get_news()
46
  news_df = predict_news_category(old_news, new_news, interpreter, label_encoder, tokenizer)
47
  if news_df is None:
48
- raise Exception('Could not generate category predictions\nAborting the database insertion.\nNo documents are inserted into the collection.')
 
 
 
 
 
 
 
49
  news_json = [*json.loads(news_df.reset_index(drop=True).to_json(orient="index")).values()]
50
  db_write.insert_news_into_db(news_json)
51
  except Exception as e:
52
  status_json = "{'status':'failure', 'message':'" + str(e) + "'}"
53
  status_code = 500
54
  raise
 
55
  logger.warning('Exiting update_news()')
56
  return Response(status_json, status=status_code, mimetype='application/json')
57
 
 
45
  new_news = get_news()
46
  news_df = predict_news_category(old_news, new_news, interpreter, label_encoder, tokenizer)
47
  if news_df is None:
48
+ raise Exception('Could not generate category predictions. Aborting the database insertion. No new articles are inserted into the collection.')
49
+
50
+ old_news_count = 0 if old_news is None else len(old_news)
51
+ new_news_count = 0 if news_df is None else len(news_df)
52
+ logger.warning(f'Old News count: {old_news_count}\nNew News count: {new_news_count}')
53
+ if new_news_count < old_news_count:
54
+ raise Exception('New news count < Old news count. Aborting the database insertion. No new articles are inserted into the collection.')
55
+
56
  news_json = [*json.loads(news_df.reset_index(drop=True).to_json(orient="index")).values()]
57
  db_write.insert_news_into_db(news_json)
58
  except Exception as e:
59
  status_json = "{'status':'failure', 'message':'" + str(e) + "'}"
60
  status_code = 500
61
  raise
62
+
63
  logger.warning('Exiting update_news()')
64
  return Response(status_json, status=status_code, mimetype='application/json')
65