Rsnarsna commited on
Commit
2bf55da
·
verified ·
1 Parent(s): 0faa5b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -230,30 +230,37 @@ html_content = """
230
  </body>
231
  </html>
232
  """
233
-
234
- # FastAPI route to display HTML interface
235
  @app.get("/", response_class=HTMLResponse)
236
- async def index(request: Request):
 
237
  status = "Running" if running else "Stopped"
238
- return HTMLResponse(html_content.replace("{{ status }}", status))
239
 
240
- # Start email processing
241
- @app.get("/start")
242
  async def start_processing():
243
  global running, loop_thread
244
  if not running:
245
  running = True
246
- loop_thread = threading.Thread(target=email_processing_loop).start()
247
- return {"message": "Email processing started."}
248
- else:
249
- return {"message": "Email processing is already running."}
250
 
251
- # Stop email processing
252
- @app.get("/stop")
253
  async def stop_processing():
254
  global running
255
- running = False
256
- return {"message": "Email processing stopped."}
 
 
257
 
258
  if __name__ == "__main__":
259
- uvicorn.run(app)
 
 
 
 
 
 
230
  </body>
231
  </html>
232
  """
233
+ # Endpoint to display the home page with the email processor's status
 
234
  @app.get("/", response_class=HTMLResponse)
235
+ async def home():
236
+ global running
237
  status = "Running" if running else "Stopped"
238
+ return HTMLResponse(content=html_content.replace("{{ status }}", status), status_code=200)
239
 
240
+ # Endpoint to start the email processing loop
241
+ @app.get("/start", response_class=HTMLResponse)
242
  async def start_processing():
243
  global running, loop_thread
244
  if not running:
245
  running = True
246
+ loop_thread = threading.Thread(target=email_processing_loop, daemon=True)
247
+ loop_thread.start()
248
+ status = "Running"
249
+ return HTMLResponse(content=html_content.replace("{{ status }}", status), status_code=200)
250
 
251
+ # Endpoint to stop the email processing loop
252
+ @app.get("/stop", response_class=HTMLResponse)
253
  async def stop_processing():
254
  global running
255
+ if running:
256
+ running = False
257
+ status = "Stopped"
258
+ return HTMLResponse(content=html_content.replace("{{ status }}", status), status_code=200)
259
 
260
  if __name__ == "__main__":
261
+ print('starting')
262
+ logging.info('starting project!...')
263
+ # running = True
264
+ # threading.Thread(target=email_processing_loop, daemon=True).start()
265
+ logging.info('...')
266
+ uvicorn.run()