def get(self, *, recording_id): """Download a Recording from OpenVidu Server Only available if OpenVidu is enabled.""" response = openvidu().get_recording(recording_id) if response.status_code == 200: recording = response.json() elif response.status_code == 404: abort(NotFound, query=f"Recording `{recording_id}` does not exist") elif response.status_code == 501: abort(NotImplemented, query="OpenVidu Server recording module is disabled") else: abort(response) if recording["url"] is None: abort( Conflict, query="The recording has not finished", ) request = openvidu().request.get(recording["url"], stream=True) # Response does not accept `headers=request.headers` so we create them ourself headers = {} for header in request.headers: headers[header] = request.headers[header] return Response( stream_with_context(request.iter_content(chunk_size=2048)), headers=headers, )
def streamed_response(): def generate(): yield 'Hello ' yield request.args['name'] yield '!' return Response(stream_with_context(generate()))
def load_fb_posts(): """ Load posts for all non-managed brands :return: Streaming Response :rtype: Response """ def generate(): brands = Brands.query.filter_by(managed=False).all() """:type: list[wiin.models.Brands]""" for brand in brands: # Fetch posts list data = json.load( urllib.urlopen( 'https://graph.facebook.com/%s/feed?access_token=%s' % (brand.fb_id, app_access_token))) while data['data']: # While posts list is not empty for d in data['data']: fb_id = d['id'] # Check if posts already exists if Posts.query.filter_by(fb_id=fb_id).count() > 0: continue message = d.get('message', None) image_url = d.get('picture', None) url = d.get('link', None) created = d['created_time'] # Skipt empty posts if not any((message, image_url, url)): continue post = Posts(brand.id, message[0:50] if message else '', message, url, image_url, created=created, fb_id=fb_id) db.session.add(post) yield json.dumps(data['data'], indent=4) # List next pages if 'paging' in data and 'next' in data['paging']: data = json.load(urllib.urlopen(data['paging']['next'])) else: data = None db.session.commit() return Response(stream_with_context(generate()), mimetype='application/json')
def video_feed(): return Response(stream_with_context(generate()), mimetype="multipart/x-mixed-replace; boundary=frame")