Spaces:
Running
Running
ksvmuralidhar
commited on
Commit
•
c01bc7e
1
Parent(s):
7094c14
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ app = Flask(__name__)
|
|
18 |
CORS(app)
|
19 |
redis_client = redis.Redis(host='localhost', port=6379, decode_responses=True)
|
20 |
logging.basicConfig(format='%(asctime)s %(message)s')
|
21 |
-
logging.
|
22 |
db = DBOperations()
|
23 |
session_id = None
|
24 |
|
@@ -28,7 +28,7 @@ REFRESH_FREQ = 300 # 300 secs = 5 mins
|
|
28 |
def is_db_fetch_reqd():
|
29 |
try:
|
30 |
env_news_time = redis_client.get('NEWSFETCHTIME')
|
31 |
-
logging.
|
32 |
fetch_flag = 1
|
33 |
if env_news_time is None:
|
34 |
redis_client.set("NEWSFETCHTIME", str(datetime.now()))
|
@@ -107,11 +107,11 @@ def elapsed_time_str(mins):
|
|
107 |
|
108 |
def fetch_from_db(fetch_flag):
|
109 |
try:
|
110 |
-
logging.
|
111 |
if fetch_flag == 1:
|
112 |
final_df = db.read_news_from_db()
|
113 |
freq_tokens = get_frequent_words_html(final_df)
|
114 |
-
logging.
|
115 |
|
116 |
final_df['_id'] = final_df['_id'].astype('str')
|
117 |
|
@@ -120,7 +120,7 @@ def fetch_from_db(fetch_flag):
|
|
120 |
else:
|
121 |
final_df = pd.read_json(redis_client.get("NEWSDF"))
|
122 |
freq_tokens = redis_client.get("NEWSWORDCLOUD")
|
123 |
-
logging.
|
124 |
|
125 |
except Exception as e:
|
126 |
print(e)
|
@@ -141,6 +141,7 @@ def index():
|
|
141 |
session_id = uuid.uuid4().hex
|
142 |
src_str = ''
|
143 |
status_code = 200
|
|
|
144 |
final_df, freq_tokens = fetch_from_db(is_db_fetch_reqd())
|
145 |
if len(final_df) > 1:
|
146 |
|
@@ -242,6 +243,7 @@ def index():
|
|
242 |
'''
|
243 |
|
244 |
result_str += '</form></div>'
|
|
|
245 |
return render_template("index.html", body=result_str), status_code
|
246 |
|
247 |
|
|
|
18 |
CORS(app)
|
19 |
redis_client = redis.Redis(host='localhost', port=6379, decode_responses=True)
|
20 |
logging.basicConfig(format='%(asctime)s %(message)s')
|
21 |
+
logging.warning(f'Is Redis available?: {redis_client.ping()}')
|
22 |
db = DBOperations()
|
23 |
session_id = None
|
24 |
|
|
|
28 |
def is_db_fetch_reqd():
|
29 |
try:
|
30 |
env_news_time = redis_client.get('NEWSFETCHTIME')
|
31 |
+
logging.warning(f'[session_id: {session_id}] fetch_time_env_var: {env_news_time}')
|
32 |
fetch_flag = 1
|
33 |
if env_news_time is None:
|
34 |
redis_client.set("NEWSFETCHTIME", str(datetime.now()))
|
|
|
107 |
|
108 |
def fetch_from_db(fetch_flag):
|
109 |
try:
|
110 |
+
logging.warning(f'[session_id: {session_id}] fetch_flag: {fetch_flag}')
|
111 |
if fetch_flag == 1:
|
112 |
final_df = db.read_news_from_db()
|
113 |
freq_tokens = get_frequent_words_html(final_df)
|
114 |
+
logging.warning(f'[session_id: {session_id}] Fetched From DB')
|
115 |
|
116 |
final_df['_id'] = final_df['_id'].astype('str')
|
117 |
|
|
|
120 |
else:
|
121 |
final_df = pd.read_json(redis_client.get("NEWSDF"))
|
122 |
freq_tokens = redis_client.get("NEWSWORDCLOUD")
|
123 |
+
logging.warning(f'[session_id: {session_id}] Fetched From Cache')
|
124 |
|
125 |
except Exception as e:
|
126 |
print(e)
|
|
|
141 |
session_id = uuid.uuid4().hex
|
142 |
src_str = ''
|
143 |
status_code = 200
|
144 |
+
logging.warning(f'[session_id: {session_id}] Entering the application')
|
145 |
final_df, freq_tokens = fetch_from_db(is_db_fetch_reqd())
|
146 |
if len(final_df) > 1:
|
147 |
|
|
|
243 |
'''
|
244 |
|
245 |
result_str += '</form></div>'
|
246 |
+
logging.warning(f'[session_id: {session_id}] Successfully rendered template')
|
247 |
return render_template("index.html", body=result_str), status_code
|
248 |
|
249 |
|