コード例 #1
0
ファイル: main.py プロジェクト: hernantz/gorkon
def index():
    form = DownloadForm(request.form)
    task = getnpop("task")  # are we processing a task already?

    if request.method == "POST" and form.validate_on_submit():

        folder = str(uuid1())  # folder where to save the file

        # list of tasks to process
        tasks = [download.s(folder, form.video_url.data)]

        if form.convert.data in ("mp3", "mp4"):
            # schedule file convertion to mp3 or mp4
            tasks.append(convert.s(form.convert.data))

        # start the chain and save the id in session for later ajax polling
        task_chain = chain(*tasks).apply_async()
        session["task"] = {"folder": folder, "task_id": task_chain.id}

        # schedule file removal in 30 min, whatever the result is
        delete.s(folder).set(countdown=1800).apply_async()

        return redirect(url_for("index"))

    return render_template("index.html", form=form, task=task)
コード例 #2
0
def download(guid=None):
    form = DownloadForm()

    if request.method == 'POST' and form.validate():
        s = hp.find_device(form.guid.data)
        if s is None:
            s = hp.find_sensor(form.guid.data)

        if s is None:
            flash("ID not found")
        else:
            try:
                df = s.get_data(head=pd.Timestamp(form.start.data),
                                tail=pd.Timestamp(form.end.data),
                                resample=form.resample.data)
            except:
                flash(
                    "Error connecting to the data storage, please try again later"
                )
            else:
                filename = '{}.csv'.format(s.key)
                filepath = safe_join(download_path, filename)
                df.to_csv(filepath, encoding='utf-8')
                del df
                gc.collect()
                return send_file(filepath, as_attachment=True)

    if guid is not None:
        form.guid.data = guid

    return render_template('download.html', form=form)
コード例 #3
0
ファイル: routes.py プロジェクト: 4215105/flask
def download_file():
    form = DownloadForm()
    if form.validate_on_submit():
        filename = secure_filename(form.filename.data)
        file_path = os.path.join(app.config["UPLOAD_FOLDER"], 'files')
        if os.path.exists(os.path.join(file_path, filename)):
            return send_from_directory(file_path, filename, as_attachment=True)
        return gettext("file [{0}] is not exists!".format(filename))
    return render_template('download.html', form=form)
コード例 #4
0
def confirmDownload(request):

    if request.method == 'POST':
        form = DownloadForm(request.POST)  # instantiating form
        if form.is_valid():
            invConvertToFormats = form.cleaned_data[
                'Select_Invariant_conversion_format']  # Which form to convert to
            grConvertToFormats = form.cleaned_data[
                'Select_Graph_conversion_format']
            dataReturn = form.cleaned_data['Select_output_type']

            for fileFormat in invConvertToFormats:
                if fileFormat == '.mat':
                    convertTo.convertLCCNpyToMat(request.session['lccfn'])
                    convertTo.convertSVDNpyToMat(request.session['SVDfn'])

                # Conversion of all files
                for inv in request.session['invariant_fns'].keys():
                    if isinstance(request.session['invariant_fns'][inv],
                                  list):  # Case of eigs
                        for fn in request.session['invariant_fns'][inv]:
                            convertTo.convertAndSave(fn, fileFormat,
                                                     getDirFromFilename(fn),
                                                     inv)
                            # TODO replace getDirFromFilename with os.path.dirname
                    else:  # case of all other invariants
                        convertTo.convertAndSave(request.session['invariant_fns'][inv], fileFormat, \
                                            getDirFromFilename(request.session['invariant_fns'][inv]) , inv)
                        # TODO replace getDirFromFilename with os.path.dirname

            for fileFormat in grConvertToFormats:
                if request.session['graphsize'] == 'big':
                    convertTo.convertGraph(request.session['bgGrfn'],
                                           fileFormat)
                elif request.session['graphsize'] == 'small':
                    convertTo.convertGraph(request.session['smGrfn'],
                                           fileFormat)

            if dataReturn == 'vd':  # View data directory
                dataUrlTail = request.session['usrDefProjDir']

                # baseurl = request.META['HTTP_HOST']
                # host = request.META['wsgi.url_scheme']
                # rooturl = host + '://' + baseurl # Originally was: 'http://mrbrain.cs.jhu.edu' # Done for http & https

                return HttpResponseRedirect('http://mrbrain.cs.jhu.edu' +
                                            dataUrlTail.replace(' ', '%20'))

            elif dataReturn == 'dz':  #Download all as zip
                return HttpResponseRedirect(get_script_prefix() + 'zipoutput')

    else:
        form = DownloadForm()

    return render_to_response('confirmDownload.html',{'downloadForm': form},\
                    context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: kchaar/dotabank-web
def download(_id):
    _replay = Replay.query.filter(Replay.id == _id).first()
    if _replay is None:
        flash("Replay {} not found.".format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    if _replay.get_s3_file() is None:
        if _replay.state != 'ARCHIVED':
            flash("Replay {} not yet stored in Dotabank.".format(_id),
                  "danger")
        else:
            flash(
                "Replay file for replay {} is missing.  This issue has been reported to the site admins and will be investigated."
                .format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    form = DownloadForm()
    key = _replay.get_s3_file()

    expires_at = (datetime.utcnow() + timedelta(
        seconds=current_app.config["REPLAY_DOWNLOAD_TIMEOUT"])).ctime()
    name = key.name
    md5 = key.etag.replace("\"", "")
    filesize = key.size
    if form.validate_on_submit(
    ) or _replay.league_id in current_app.config['CAPTCHA_LEAGUE_EXCEPTIONS']:
        url = key.generate_url(current_app.config["REPLAY_DOWNLOAD_TIMEOUT"])

        download_log_entry = ReplayDownload(
            _replay.id,
            current_user.get_id() if current_user else None)
        db.session.add(download_log_entry)
        db.session.commit()

        return render_template("replays/download_granted.html",
                               title="Download replay {} - Dotabank".format(
                                   _replay.id),
                               replay=_replay,
                               expires_at=expires_at,
                               name=name,
                               md5=md5,
                               filesize=filesize,
                               url=url)

    return render_template("replays/download.html",
                           title="Download replay {} - Dotabank".format(
                               _replay.id),
                           replay=_replay,
                           name=name,
                           md5=md5,
                           filesize=filesize,
                           form=form)
コード例 #6
0
def downloads_new():
    download = Download()
    form = DownloadForm(request.form, download)
    if form.validate_on_submit():
        f = request.files['url']
        if f:
            filename = secure_filename(f.filename)
            f.save(os.path.join(neobug.config['UPLOAD_FOLDER'], filename))
            form.populate_obj(download)
            download.url = 'static/uploads/' + filename
            download.save()
        return redirect('/downloads')
    return render_template('downloads_new.html',
                           form=form)
コード例 #7
0
ファイル: views.py プロジェクト: amondal2/MR-connectome
def confirmDownload(request):

  if request.method == 'POST':
    form = DownloadForm(request.POST) # instantiating form
    if form.is_valid():
      invConvertToFormats = form.cleaned_data['Select_Invariant_conversion_format'] # Which form to convert to
      grConvertToFormats = form.cleaned_data['Select_Graph_conversion_format']
      dataReturn = form.cleaned_data['Select_output_type']

      for fileFormat in invConvertToFormats:
        if fileFormat == '.mat':
          convertTo.convertLCCNpyToMat(request.session['lccfn'])
          convertTo.convertSVDNpyToMat(request.session['SVDfn'])

        # Conversion of all files
        for inv in request.session['invariant_fns'].keys():
          if isinstance(request.session['invariant_fns'][inv], list): # Case of eigs
            for fn in request.session['invariant_fns'][inv]:
              convertTo.convertAndSave(fn, fileFormat, getDirFromFilename(fn), inv)
              # TODO replace getDirFromFilename with os.path.dirname
          else: # case of all other invariants
            convertTo.convertAndSave(request.session['invariant_fns'][inv], fileFormat, \
                                getDirFromFilename(request.session['invariant_fns'][inv]) , inv)
            # TODO replace getDirFromFilename with os.path.dirname

      for fileFormat in grConvertToFormats:
        if request.session['graphsize'] == 'big':
          convertTo.convertGraph(request.session['bgGrfn'], fileFormat)
        elif request.session['graphsize'] == 'small':
          convertTo.convertGraph(request.session['smGrfn'], fileFormat)

      if dataReturn == 'vd': # View data directory
        dataUrlTail = request.session['usrDefProjDir']

        # baseurl = request.META['HTTP_HOST']
        # host = request.META['wsgi.url_scheme']
        # rooturl = host + '://' + baseurl # Originally was: 'http://mrbrain.cs.jhu.edu' # Done for http & https

        return HttpResponseRedirect('http://mrbrain.cs.jhu.edu' + dataUrlTail.replace(' ','%20'))

      elif dataReturn == 'dz': #Download all as zip
        return HttpResponseRedirect(get_script_prefix()+'zipoutput')

  else:
    form = DownloadForm()

  return render_to_response('confirmDownload.html',{'downloadForm': form},\
                  context_instance=RequestContext(request))
コード例 #8
0
def download_query():
    form = DownloadForm()
    symbol = request.args.get('symbol')
    if request.method == 'POST':
        if symbol:
            form.symbol.data = symbol
        symbol = form.symbol.data.upper()
        start = form.contract_from.data
        end = form.contract_to.data
        results = File.query.filter(File.symbol == symbol,
                                    File.contract_date.between(start,
                                                               end)).all()
        if results:
            return redirect(
                url_for('resource.show_results',
                        symbol=symbol,
                        start=start,
                        end=end))
        else:
            flash('The file does not exist.', 'danger')
            return redirect(request.url)
    return render_template('resource/download_query.html',
                           title='Download_query',
                           form=form,
                           current_user=current_user)
コード例 #9
0
ファイル: app.py プロジェクト: xumarcus/ytdl20
def download():
    form = DownloadForm(request.form)
    if form.validate_on_submit():
        config = {
            'format': '%s+bestaudio/best' % form.download_format.data,
            'outtmpl': '%(format_id)s-%(id)s.%(ext)s',
            'merge_output_format': 'mkv'
        }
        with youtube_dl.YoutubeDL(config) as ydl:
            with suppress(youtube_dl.DownloadError):
                info = ydl.extract_info(form.download_url.data, download=True)
                filename = '%(format_id)s-%(id)s.mkv' % info
                attachment_filename = '%(title)s.mkv' % info
                return send_file(filename,
                                 as_attachment=True,
                                 attachment_filename=attachment_filename)
    return redirect('/')
コード例 #10
0
ファイル: views.py プロジェクト: TimotheeJeannin/dotabank-web
def download(_id):
    _replay = Replay.query.filter(Replay.id == _id).first()
    if _replay is None:
        flash("Replay {} not found.".format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    if _replay.get_s3_file() is None:
        if _replay.state != 'ARCHIVED':
            flash("Replay {} not yet stored in Dotabank.".format(_id), "danger")
        else:
            flash("Replay file for replay {} is missing.  This issue has been reported to the site admins and will be investigated.".format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    form = DownloadForm()
    key = _replay.get_s3_file()

    expires_at = (datetime.utcnow() + timedelta(seconds=current_app.config["REPLAY_DOWNLOAD_TIMEOUT"])).ctime()
    name = key.name
    md5 = key.etag.replace("\"", "")
    filesize = key.size
    if form.validate_on_submit() or _replay.league_id in current_app.config['CAPTCHA_LEAGUE_EXCEPTIONS']:
        url = key.generate_url(current_app.config["REPLAY_DOWNLOAD_TIMEOUT"])

        download_log_entry = ReplayDownload(
            _replay.id,
            current_user.get_id() if current_user else None
        )
        db.session.add(download_log_entry)
        db.session.commit()

        return render_template("replays/download_granted.html",
                               title="Download replay {} - Dotabank".format(_replay.id),
                               replay=_replay,
                               expires_at=expires_at,
                               name=name,
                               md5=md5,
                               filesize=filesize,
                               url=url)

    return render_template("replays/download.html",
                           title="Download replay {} - Dotabank".format(_replay.id),
                           replay=_replay,
                           name=name,
                           md5=md5,
                           filesize=filesize,
                           form=form)
コード例 #11
0
ファイル: website.py プロジェクト: MatteusDeloge/website
def download(guid=None):
    form = DownloadForm()

    if request.method == 'POST' and form.validate():
        s = hp.find_device(form.guid.data)
        if s is None:
            s = hp.find_sensor(form.guid.data)

        if s is None:
            flash("ID not found")
        else:
            try:
                # We need to connect and disconnect with tmpo
                # to make sure the website doesn't lock access to the sqlite
                hp.init_tmpo()
                tmpos = hp.get_tmpos()
                output = StringIO()
                df = s.get_data(
                        head=pd.Timestamp(form.start.data),
                        tail=pd.Timestamp(form.end.data),
                        resample=form.resample.data
                )
                tmpos.dbcon.close()
            except:
                # This will happen if another process is currently using the tmpo
                flash("Error connecting to the data storage, please try again later")
            else:
                df.to_csv(output, encoding='utf-8')
                output.seek(0)
                return send_file(
                        output,
                        mimetype="text/csv",
                        as_attachment=True,
                        attachment_filename='{}.csv'.format(s.key)
                )
    if guid is not None:
        form.guid.data = guid

    return render_template(
            'download.html',
            form=form
    )
コード例 #12
0
ファイル: main.py プロジェクト: javieroc/listen-2-pytube
def index():
    form = DownloadForm(request.form)

    if request.method == 'POST' and form.validate_on_submit():
        url = form.url.data
        media_format = form.media_format.data
        download_token = form.download_token.data

        if media_format == 'video':
            filename = download_video(url)
        else:
            filename = download_music(url)

        response = make_response(
            send_from_directory('./data', filename, as_attachment=True))
        response.set_cookie('download_token', download_token)
        return response

    return render_template('index.html',
                           form=form,
                           redirect_url=url_for('index'))
コード例 #13
0
ファイル: views.py プロジェクト: hqychr/MR-connectome
def confirmDownload(request):

  if request.method == 'POST':
    form = DownloadForm(request.POST) # instantiating form
    if form.is_valid():

      dataReturn = form.cleaned_data['Select_output_type']

      if dataReturn == 'vd': # View data directory
        dataUrlTail = request.session['usrDefProjDir']

        dwnldLoc = request.META['wsgi.url_scheme'] + '://' + \
                    request.META['HTTP_HOST'] + dataUrlTail.replace(' ','%20')

        return HttpResponseRedirect(dwnldLoc)

      elif dataReturn == 'dz': #Download all as zip
        return HttpResponseRedirect(get_script_prefix()+'zipoutput')
  else:
    form = DownloadForm()
  return render_to_response('confirmDownload.html',{'downloadForm': form},\
                  context_instance=RequestContext(request))
コード例 #14
0
ファイル: app.py プロジェクト: xumarcus/ytdl20
 def __post_init__(self):
     self.stream_form = StreamForm()
     self.stream_form.stream_url.choices = [
         (dash.url, '%s (%s)' % (AUDIO_FORMATS[dash.format_id],
                                 humanfriendly.format_size(dash.filesize)))
         for dash in self.formats if dash.format_id in AUDIO_FORMATS
     ]
     self.download_form = DownloadForm()
     self.download_form.download_format.choices = [
         (dash.format_id,
          '%s (%s)' % (VIDEO_FORMATS[dash.format_id],
                       humanfriendly.format_size(dash.filesize)))
         for dash in self.formats if dash.format_id in VIDEO_FORMATS
     ]
コード例 #15
0
ファイル: website.py プロジェクト: saroele/website
def download(guid=None):
    form = DownloadForm()

    if request.method == 'POST' and form.validate():
        s = hp.find_device(form.guid.data)
        if s is None:
            s = hp.find_sensor(form.guid.data)

        if s is None:
            flash("ID not found")
        else:
            try:
                df = s.get_data(
                    head=pd.Timestamp(form.start.data),
                    tail=pd.Timestamp(form.end.data),
                    resample=form.resample.data
                )
            except:
                flash("Error connecting to the data storage, please try again later")
            else:
                filename = '{}.csv'.format(s.key)
                filepath = safe_join("static/downloads", filename)
                df.to_csv(filepath, encoding='utf-8')
                del df
                gc.collect()
                return send_file(
                    filepath,
                    as_attachment=True
                )

    if guid is not None:
        form.guid.data = guid

    return render_template(
        'download.html',
        form=form
    )
コード例 #16
0
def download(guid=None):
    form = DownloadForm()

    if request.method == 'POST' and form.validate():
        s = hp.find_device(form.guid.data)
        if s is None:
            s = hp.find_sensor(form.guid.data)

        if s is None:
            flash("ID not found")
        else:
            try:
                # We need to connect and disconnect with tmpo
                # to make sure the website doesn't lock access to the sqlite
                hp.init_tmpo()
                tmpos = hp.get_tmpos()
                output = StringIO()
                df = s.get_data(head=pd.Timestamp(form.start.data),
                                tail=pd.Timestamp(form.end.data),
                                resample=form.resample.data)
                tmpos.dbcon.close()
            except:
                # This will happen if another process is currently using the tmpo
                flash(
                    "Error connecting to the data storage, please try again later"
                )
            else:
                df.to_csv(output, encoding='utf-8')
                output.seek(0)
                return send_file(output,
                                 mimetype="text/csv",
                                 as_attachment=True,
                                 attachment_filename='{}.csv'.format(s.key))
    if guid is not None:
        form.guid.data = guid

    return render_template('download.html', form=form)
コード例 #17
0
def index():
    '''
    Index function
    '''
    global file_downloaded
    global file_cid
    form = DownloadForm()
    #In the case that a download is already started returning the page that shows the graphs
    if file_downloaded != 0:
        return render_template('plot.html', file_cid=file_cid)
    #If the request is a POST an user requests a download
    if request.method == 'POST':
        if form.validate_on_submit():
            #Getting the CID of the content from the form
            file_cid = request.form['file_cid']
            #Starting file download in another thread to not wait for the response
            thread = threading.Thread(target=get_file, args=(file_cid, ))
            thread.start()
            #Returning the page that shows the graphs
            return render_template('plot.html', file_cid=file_cid)
    else:
        #If the request is a GET returning the index page
        file_downloaded = 0
        return render_template('index.html', form=form)
コード例 #18
0
def download(filename=None, threshold=0.9):
    form = DownloadForm()
    logging.info("download filename(2)= %s", form.filename.data)
    logging.info("download threshold(2) = %s", form.threshold.data)
    threshold = float(form.threshold.data)

    filename = form.filename.data
    download_list = request.form.getlist("include")

    (sample_return_data, snp_return_data,
     msg) = ds.get_rslist_file_data(app.config['UPLOAD_DIR'] + "/" + filename,
                                    threshold, download_list)
    zipfilename = filename + "_file_results.zip"
    body = ds.make_zipfile(sample_return_data, snp_return_data,
                           app.config['UPLOAD_DIR'], zipfilename)
    response = make_response(body)
    response.headers[
        "Content-Disposition"] = "attachment; filename=" + zipfilename
    return response
コード例 #19
0
def uploaded_file(filename=None, threshold=0.9):
    """
  Display upload form
  """
    logging.info("uploaded %s", filename)
    form = UploadForm()
    filename = ""
    msg = ""
    if form.validate_on_submit():
        threshold = form.threshold.data
        if threshold == None:
            threshold = 0.9
        filen = form.filename.data
        if filen and allowed_file(filen.filename):
            filename = secure_filename(filen.filename)
            logging.info("uploaded filename = %s (%f)", filename, threshold)
            filen.save(os.path.join(app.config['UPLOAD_DIR'], filename))
            (variant_data, msg) = ds.get_variant_data_for_file(
                app.config['UPLOAD_DIR'] + "/" + filename, threshold)
            logging.info("variant_data size = %d, msg = %s", len(variant_data),
                         msg)
        dnform = DownloadForm()
        dnform.filename.data = filename
        dnform.filename.readonly = True
        dnform.threshold.data = threshold
        dnform.threshold.readonly = True
        return render_template('uploaded.html',
                               title='Upload',
                               form=dnform,
                               variant_data=variant_data,
                               msg=msg,
                               db_name=ds.get_db_name())
    else:
        logging.info("form validation failed / not run %s, %s", filename,
                     threshold)
    logging.info("uploaded_file - drop through")
    return render_template('upload_file.html',
                           form=form,
                           filename=filename,
                           threshold=threshold)
コード例 #20
0
def csv_download():

    form = DownloadForm(request.form)

    f = StringIO()
    writer = csv.writer(f, quotechar='"', lineterminator="\n")

    writer.writerow(['検索ワード', form.search_word.data])
    writer.writerow(['合計1週間のツイート数', form.total.data])
    writer.writerow(['1週間毎のツイート数'])
    writer.writerow(covert_string_to_array(form.oneweek.data))
    writer.writerow(covert_string_to_array(form.counts.data))

    res = make_response()
    res.data = f.getvalue().encode('cp932', 'ignore')
    res.headers['Content-Type'] = 'text/csv'
    res.headers['Content-Disposition'] = \
        'attachment; filename=' +\
        datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') +\
        '-oneweek-tweet.csv'

    return res
コード例 #21
0
def submit(request):
    dform = DownloadForm(request.POST or None)
    if dform.is_valid():
      dform.save()
      return redirect(reverse('free_data'))
    return render(request, 'download.html', context={'dform': dform})
コード例 #22
0
ファイル: views.py プロジェクト: revanth-reddy/ns-3-AppStore
def modifyDownload(request, num):
    existing = False
    App = apps.get_model('apps', 'App')
    Download = apps.get_model('apps', 'Download')
    Release = apps.get_model('apps', 'Release')
    try:
        app = App.objects.get(id=num)
    except:
        context = {
            'message': "Requested App does not Exist!",
            'go_back_to_url': "/app/" + app.name,
            'go_back_to_title': "App Page",
        }
        return render(request, 'message.html', context)
    if Download.objects.filter(app=app).exists():
        existing = True
        edit_download = Download.objects.get(app=app)
    if request.user.is_staff or request.user in app.editors.all():
        if request.method == 'GET':
            if existing:
                form = DownloadForm(instance=edit_download, current_app=app)
            else:
                form = DownloadForm(current_app=app)
        elif request.method == 'POST':
            if existing:
                form = DownloadForm(request.POST,
                                    instance=edit_download,
                                    current_app=app)
            else:
                form = DownloadForm(request.POST, current_app=app)
            if form.is_valid():
                if existing:
                    instance = form.save()
                    release = None
                    releases = Release.objects.filter(app=instance.app)
                    if releases:
                        release = releases.latest('date')
                    choice = instance.download_option
                    link = "https://ns-apps.washington.edu/" + instance.app.name + "/#cy-app-instructions-tab"
                    if choice == 'I':
                        instance.download_link = link
                    elif choice == 'D':
                        instance.download_link = release.url
                        if not release:
                            instance.download_link = link
                    elif choice == 'U':
                        instance.download_link = instance.external_url
                        if not instance.external_url:
                            instance.download_link = link
                    if not instance.default_release:
                        instance.default_release = release
                    print instance.download_link
                    instance.save()
                else:
                    download = form.save(commit=False)
                    download.app = app
                    download.save()
                context = {
                    'message': "Download Details modified Successfully!",
                    'go_back_to_url': "/app/" + app.name,
                    'go_back_to_title': "App Page",
                }
                return render(request, 'message.html', context)
    else:
        context = {
            'message': "You are not authorized to view this page!",
            'go_back_to_url': "/app/" + app.name,
            'go_back_to_title': "App Page",
        }
        return render(request, 'message.html', context)
    return render(request, 'download.html', {'form': form})