<commit_before>from flask import render_template, url_for, redirect, request, g,\
                  make_response
from datetime import datetime, timedelta, timezone
import lib.twitter
import lib.mastodon
from lib.auth import require_auth, csrf,\
                     get_viewer
from model import Session, TwitterArchive, MastodonApp, MastodonInstance
from app import app, db, sentry, limiter, imgproxy
import tasks
from zipfile import BadZipFile
from twitter import TwitterError
from urllib.error import URLError
import lib.version
import lib.settings
import lib.json
import re


@app.route('/')
def index():
    viewer = get_viewer()
    if viewer:
        return render_template(
                'logged_in.html',
                scales=lib.interval.SCALES,
                tweet_archive_failed='tweet_archive_failed' in request.args,
                settings_error='settings_error' in request.args,
                viewer_json=lib.json.account(viewer),
                viewer_avatar=url_for(
                    'avatar',
                    identifier=imgproxy.identifier_for(viewer.avatar_url)),
                )
    else:
        instances = (
                MastodonInstance.query
                .filter(MastodonInstance.popularity > 13)
                .order_by(db.desc(MastodonInstance.popularity),
                          MastodonInstance.instance)
                .limit(5))
        return render_template(
                'index.html',
                mastodon_instances=instances,
                twitter_login_error='twitter_login_error' in request.args)


@app.route('/login/twitter')
@limiter.limit('3/minute')
def twitter_login_step1():
    try:
        return redirect(lib.twitter.get_login_url(
            callback=url_for('twitter_login_step2', _external=True),
            **app.config.get_namespace("TWITTER_")
            ))
    except (TwitterError, URLError):
        if sentry:
            sentry.captureException()
        return redirect(
                url_for('index', twitter_login_error='', _anchor='log_in'))


def login(account_id):
    session = Session(account_id=account_id)
    db.session.add(session)
    db.session.commit()

    session.account.dormant = False
    db.session.commit()

    tasks.fetch_acc.s(account_id).apply_async(routing_key='high')

    return session


@app.route('/login/twitter/callback')
@limiter.limit('3/minute')
def twitter_login_step2():
    try:
        oauth_token = request.args['oauth_token']<commit_msg>make rate limits more lenient on user-facing pages<commit_after>from flask import render_template, url_for, redirect, request, g,\
                  make_response
from datetime import datetime, timedelta, timezone
import lib.twitter
import lib.mastodon
from lib.auth import require_auth, csrf,\
                     get_viewer
from model import Session, TwitterArchive, MastodonApp, MastodonInstance
from app import app, db, sentry, limiter, imgproxy
import tasks
from zipfile import BadZipFile
from twitter import TwitterError
from urllib.error import URLError
import lib.version
import lib.settings
import lib.json
import re


@app.route('/')
def index():
    viewer = get_viewer()
    if viewer:
        return render_template(
                'logged_in.html',
                scales=lib.interval.SCALES,
                tweet_archive_failed='tweet_archive_failed' in request.args,
                settings_error='settings_error' in request.args,
                viewer_json=lib.json.account(viewer),
                viewer_avatar=url_for(
                    'avatar',
                    identifier=imgproxy.identifier_for(viewer.avatar_url)),
                )
    else:
        instances = (
                MastodonInstance.query
                .filter(MastodonInstance.popularity > 13)
                .order_by(db.desc(MastodonInstance.popularity),
                          MastodonInstance.instance)
                .limit(5))
        return render_template(
                'index.html',
                mastodon_instances=instances,
                twitter_login_error='twitter_login_error' in request.args)


@app.route('/login/twitter')
@limiter.limit('10/minute')
def twitter_login_step1():
    try:
        return redirect(lib.twitter.get_login_url(
            callback=url_for('twitter_login_step2', _external=True),
            **app.config.get_namespace("TWITTER_")
            ))
    except (TwitterError, URLError):
        if sentry:
            sentry.captureException()
        return redirect(
                url_for('index', twitter_login_error='', _anchor='log_in'))


def login(account_id):
    session = Session(account_id=account_id)
    db.session.add(session)
    db.session.commit()

    session.account.dormant = False
    db.session.commit()

    tasks.fetch_acc.s(account_id).apply_async(routing_key='high')

    return session


@app.route('/login/twitter/callback')
@limiter.limit('10/minute')
def twitter_login_step2():
    try:
        oauth_token = request.args['oauth_token']
{'fraction_non_alphanumeric': 0.09406830437387657, 'fraction_numerical': 0.0035949670461354103, 'mean_word_length': 2.4753643303261623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '188292', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1406, 'n_words': 282}