lalithadevi commited on
Commit
1da191b
1 Parent(s): 0b44a23

Update app.py

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