Marthee commited on
Commit
efd2757
·
verified ·
1 Parent(s): d4881b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -101,26 +101,25 @@ def getInfo2toMeasure():
101
  @app.route('/getprojectnames/',methods=['GET'])
102
  def getprjnamesfromTestAPI():
103
  progress_updates = [] # Shared list to store progress
 
104
  def generate_progressProjnames():
105
- yield "data: 10\n\n"
106
- sys.stdout.flush() # Force immediate send
107
-
108
- prjnames, prjids = API.getPrjNames(progress_callback=lambda p: progress_updates.append(p))
109
-
110
  while progress_updates:
111
- progress = progress_updates.pop(0)
112
  yield f"data: {progress}\n\n"
113
- sys.stdout.flush()
114
-
115
- yield "data: 80\n\n"
116
- sys.stdout.flush()
117
-
118
- yield "data: 100\n\n"
119
- sys.stdout.flush()
120
-
121
- result = json.dumps([prjnames, prjids])
122
  yield f"data: {result}\n\n"
123
- sys.stdout.flush()
 
 
 
124
 
125
 
126
  @app.route('/getprojectparts/<jsdata>',methods=['GET'])
 
101
  @app.route('/getprojectnames/',methods=['GET'])
102
  def getprjnamesfromTestAPI():
103
  progress_updates = [] # Shared list to store progress
104
+
105
  def generate_progressProjnames():
106
+ yield f"data: 10\n\n" # Initial progress
107
+ # Call retrieveProjects and pass a callback to update the shared list
108
+ prjnames,prjids=API.getPrjNames( progress_callback=lambda p: progress_updates.append(p))
109
+ # Continuously yield progress updates from the shared list
110
+
111
  while progress_updates:
112
+ progress = progress_updates.pop(0) # Get the next progress value
113
  yield f"data: {progress}\n\n"
114
+ # Final progress and result
115
+ yield f"data: 80\n\n"
116
+ yield f"data: 100\n\n"
117
+ result = json.dumps([prjnames,prjids])
 
 
 
 
 
118
  yield f"data: {result}\n\n"
119
+ return Response(generate_progressProjnames(), content_type='text/event-stream')
120
+
121
+
122
+
123
 
124
 
125
  @app.route('/getprojectparts/<jsdata>',methods=['GET'])