ksvmuralidhar commited on
Commit
cdbde97
1 Parent(s): 480dffe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -1,8 +1,9 @@
1
  import numpy as np
2
  import pandas as pd
3
  from dateutil import parser
4
- from flask import Flask, render_template
5
- from flask_cors import cross_origin, CORS
 
6
  from db_operations.db_operations import DBOperations
7
  import logging
8
  import traceback
@@ -15,8 +16,8 @@ from word_cloud import get_frequent_words_html
15
  from config import NEWS_RETENTION_SECONDS, UK_EDITION_URL
16
 
17
 
18
- app = Flask(__name__)
19
- CORS(app)
20
  redis_client = redis.Redis(host='localhost', port=6379, decode_responses=True)
21
  logging.basicConfig(format='%(asctime)s %(message)s')
22
  logging.warning(f'Is Redis available?: {redis_client.ping()}')
@@ -106,12 +107,12 @@ def elapsed_time_str(mins):
106
 
107
 
108
 
109
- def fetch_from_db(fetch_flag):
110
  try:
111
  logging.warning(f'[session_id: {session_id}] fetch_flag: {fetch_flag}')
112
  if fetch_flag == 1:
113
- final_df = db.read_news_from_db()
114
- freq_tokens = get_frequent_words_html(final_df)
115
  logging.warning(f'[session_id: {session_id}] Fetched From DB')
116
 
117
  final_df['_id'] = final_df['_id'].astype('str')
@@ -132,8 +133,7 @@ def fetch_from_db(fetch_flag):
132
 
133
 
134
  @app.route("/")
135
- @cross_origin()
136
- def index():
137
  """
138
  Entry point
139
  """
@@ -143,7 +143,7 @@ def index():
143
  src_str = ''
144
  status_code = 200
145
  logging.warning(f'[session_id: {session_id}] Entering the application')
146
- final_df, freq_tokens = fetch_from_db(is_db_fetch_reqd())
147
  if len(final_df) > 1:
148
 
149
  final_df["parsed_date"] = [correct_date(date_) for date_ in final_df['parsed_date']]
@@ -249,9 +249,9 @@ def index():
249
  result_str += '</form></div>'
250
  logging.warning(f'[session_id: {session_id}] Successfully rendered template')
251
  gc.collect()
252
- return render_template("index.html", body=result_str), status_code
253
 
254
 
255
  if __name__ == "__main__":
256
- app.run(host="0.0.0.0", port=7860, workers=3, threads=3) # workers=(2*ncores) + 1, threads= (2 to 4*ncores) + 1
257
 
 
1
  import numpy as np
2
  import pandas as pd
3
  from dateutil import parser
4
+ from quart_cors import cors
5
+ from quart import Quart
6
+ from quart import render_template
7
  from db_operations.db_operations import DBOperations
8
  import logging
9
  import traceback
 
16
  from config import NEWS_RETENTION_SECONDS, UK_EDITION_URL
17
 
18
 
19
+ app = Quart(__name__)
20
+ app = cors(app, allow_origin="*")
21
  redis_client = redis.Redis(host='localhost', port=6379, decode_responses=True)
22
  logging.basicConfig(format='%(asctime)s %(message)s')
23
  logging.warning(f'Is Redis available?: {redis_client.ping()}')
 
107
 
108
 
109
 
110
+ async def fetch_from_db(fetch_flag):
111
  try:
112
  logging.warning(f'[session_id: {session_id}] fetch_flag: {fetch_flag}')
113
  if fetch_flag == 1:
114
+ final_df = await db.read_news_from_db()
115
+ freq_tokens = await get_frequent_words_html(final_df)
116
  logging.warning(f'[session_id: {session_id}] Fetched From DB')
117
 
118
  final_df['_id'] = final_df['_id'].astype('str')
 
133
 
134
 
135
  @app.route("/")
136
+ async def index():
 
137
  """
138
  Entry point
139
  """
 
143
  src_str = ''
144
  status_code = 200
145
  logging.warning(f'[session_id: {session_id}] Entering the application')
146
+ final_df, freq_tokens = await fetch_from_db(is_db_fetch_reqd())
147
  if len(final_df) > 1:
148
 
149
  final_df["parsed_date"] = [correct_date(date_) for date_ in final_df['parsed_date']]
 
249
  result_str += '</form></div>'
250
  logging.warning(f'[session_id: {session_id}] Successfully rendered template')
251
  gc.collect()
252
+ return await render_template("index.html", body=result_str), status_code
253
 
254
 
255
  if __name__ == "__main__":
256
+ app.run(host="0.0.0.0", port=7860, workers=5, threads=5) # workers=(2*ncores) + 1, threads= (2 to 4*ncores) + 1
257