<commit_before>#!/usr/bin/env python
import io
import os
import sys
import base64

if sys.version_info.major == 2:
    import ConfigParser as configparser
else:
    import configparser

from flask import Flask, render_template, redirect, request, url_for, \
    session, Response, send_file
import dropbox

APP_KEY = os.getenv('DROPBOX_KEY')
APP_SECRET = os.getenv('DROPBOX_SECRET')

app = Flask(__name__)
app.secret_key = base64.b64encode(os.urandom(64))


def get_flow():
    redirect_uri = url_for('finish', _external=True)

    return dropbox.client.DropboxOAuth2Flow(APP_KEY, APP_SECRET,
            redirect_uri, session, "dropbox-auth-csrf-token")


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/authorise')
def authorize():
    url = get_flow().start()
    return redirect(url)


@app.route('/finish')
def finish():
    access_token, _, _ = get_flow().finish(request.args)

    return send_file(build_config(access_token), mimetype="text/ini",
            as_attachment=True,
            attachment_filename="flysight-manager.ini")

def build_config(token):
    defaults = {
            'mountpoint': 'flysight',<commit_msg>Use https links for the callback<commit_after>#!/usr/bin/env python
import io
import os
import sys
import base64

if sys.version_info.major == 2:
    import ConfigParser as configparser
else:
    import configparser

from flask import Flask, render_template, redirect, request, url_for, \
    session, Response, send_file
import dropbox

APP_KEY = os.getenv('DROPBOX_KEY')
APP_SECRET = os.getenv('DROPBOX_SECRET')

app = Flask(__name__)
app.secret_key = base64.b64encode(os.urandom(64))


def get_flow():
    redirect_uri = url_for('finish', _external=True, _scheme='https')

    return dropbox.client.DropboxOAuth2Flow(APP_KEY, APP_SECRET,
            redirect_uri, session, "dropbox-auth-csrf-token")


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/authorise')
def authorize():
    url = get_flow().start()
    return redirect(url)


@app.route('/finish')
def finish():
    access_token, _, _ = get_flow().finish(request.args)

    return send_file(build_config(access_token), mimetype="text/ini",
            as_attachment=True,
            attachment_filename="flysight-manager.ini")

def build_config(token):
    defaults = {
            'mountpoint': 'flysight',
{'fraction_non_alphanumeric': 0.1261564339781329, 'fraction_numerical': 0.008410428931875526, 'mean_word_length': 4.160520607375271, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1004093', 'n_tokens_mistral': 807, 'n_tokens_neox': 770, 'n_words': 163}