Example #1
0
    def upload_file(self):
        form = UploadEpgForm()
        if form.validate_on_submit():
            file_handle = form.file.data
            content = file_handle.read().decode('utf-8')
            url_set = set()
            for line in content.split():
                url_set.add(line.strip())

            for uniq in url_set:
                epg = Epg()
                epg.uri = uniq
                epg.save()

        return redirect(url_for('EpgView:epg'))
Example #2
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
Example #3
0
    def add(self):
        form = EpgForm(obj=Epg())
        if request.method == 'POST' and form.validate_on_submit():
            new_entry = form.make_entry()
            new_entry.save()
            return jsonify(status='ok'), 200

        return render_template('epg/add.html', form=form)
Example #4
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
Example #5
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)
Example #6
0
 def epg(self):
     epgs = Epg.objects()
     return render_template('provider/epg.html', epgs=epgs)
Example #7
0
 def show(self):
     epgs = Epg.objects()
     return render_template('epg/show.html', epgs=epgs)