Exemplo n.º 1
0
    def update_urls(self):
        epgs = Epg.objects()
        epg_service_in_directory = app.config.get('EPG_IN_DIRECTORY')

        result = []
        for index, epg in enumerate(epgs):
            try:
                path, name = download_file(epg.uri, get_epg_tmp_folder(),
                                           epg.extension, 10)
            except Exception:
                result.append({'url': epg.uri, 'status': False})
                continue

            name = '({0})_{1}'.format(index, name)
            out_path = os.path.expanduser(
                os.path.join(epg_service_in_directory, name))
            status = True
            if name.endswith('.gz'):
                try:
                    gunzip(path, out_path)
                except Exception:
                    status = False
            else:
                shutil.copy(path, out_path)

            os.unlink(path)
            result.append({'path': path, 'status': status})

        return jsonify(status='ok', result=result), 200
Exemplo n.º 2
0
    def remove(self):
        sid = request.form['sid']
        epg = Epg.objects(id=sid).first()
        if epg:
            epg.delete()
            return jsonify(status='ok'), 200

        return jsonify(status='failed'), 404
Exemplo n.º 3
0
    def edit(self, sid):
        epg = Epg.objects(id=sid).first()
        form = EpgForm(obj=epg)

        if request.method == 'POST' and form.validate_on_submit():
            epg = form.update_entry(epg)
            epg.save()
            return jsonify(status='ok'), 200

        return render_template('epg/edit.html', form=form)
Exemplo n.º 4
0
 def epg(self):
     epgs = Epg.objects()
     return render_template('provider/epg.html', epgs=epgs)
Exemplo n.º 5
0
 def show(self):
     epgs = Epg.objects()
     return render_template('epg/show.html', epgs=epgs)