<commit_before>import aiohttp_jinja2

from aiohttp import web
from aiohttp_session import get_session
from bson import ObjectId

# flake8: noqa

class SiteHandler:

    def __init__(self, mongo):
        self._mongo = mongo

    @property
    def mongo(self):
        return self._mongo

    @aiohttp_jinja2.template('timeline.html')
    async def timeline(self, request):
        session = await get_session(request)
        user_id = session.get('user_id')

        if user_id is None:
            router = request.app.router
            location = router['public_timeline'].url()
            raise web.HTTPFound(location=location)

        query = {'who_id': ObjectId(user_id)}
        filter = {'whom_id': 1}
        followed = await self.mongo.follower.find_one(query, filter)
        if followed is None:
            followed = {'whom_id': []}

        query = {'$or': [{'author_id': ObjectId(user_id)},
                         {'author_id': {'$in': followed['whom_id']}}]}
        messages = self.mongo.message.find(query).sort('pub_date', -1)
        endpoint = request.match_info.route.name
        return {"messages": messages,
                "endpoint": endpoint}

    @aiohttp_jinja2.template('timeline.html')
    async def public_timeline(self, request):
        messages = await (self.mongo.message
                          .find()
                          .sort('pub_date', -1)
                          .to_list(30))
        return {"messages": messages,
                "endpoint": request.match_info.route.name}

    @aiohttp_jinja2.template('timeline.html')
    async def user_timeline(self, request):
        username = request.match_info['username']
        profile_user = await self.mongo.user.find_one({'username': username})
        if profile_user is None:
            raise web.HTTPNotFound()
        followed = False
        session = await get_session(request)
        user_id = session.get('user_id')
        if user_id:
            followed = await self.mongo.follower.find_one(
                {'who_id': ObjectId(session['user_id']),
                 'whom_id': {'$in': [ObjectId(profile_user['_id'])]}}) is not None

        messages = await (self.mongo.message.find({'author_id': ObjectId(profile_user['_id'])})
                          .sort('pub_date', -1)
                          .to_list(30))

        return {"messages": messages,
                "followed": followed,
                "profile_user": profile_user}



<EMAIL>('/<username>')
#def user_timeline(username):
#    """Display's a users tweets."""
#    profile_user = mongo.db.user.find_one({'username': username})
#    if profile_user is None:
#        abort(404)
#    followed = False
#    if g.user:
#        followed = mongo.db.follower.find_one(
#            {'who_id': ObjectId(session['user_id']),
#             'whom_id': {'$in': [ObjectId(profile_user['_id'])]}}) is not None
#    messages = mongo.db.message.find(
#        {'author_id': ObjectId(profile_user['_id'])}).sort('pub_date', -1)
#    return render_template('timeline.html', messages=messages,
#                           followed=followed, profile_user=profile_user)

    @aiohttp_jinja2.template('timeline.html')
    async def login(self, request):
        return {}<commit_msg>fix couple endpoints in mongotwit demo<commit_after>import aiohttp_jinja2

from aiohttp import web
from aiohttp_session import get_session
from bson import ObjectId

from . import db
from .security import generate_password_hash, check_password_hash
from .utils import redirect

# flake8: noqa

class SiteHandler:

    def __init__(self, mongo):
        self._mongo = mongo

    @property
    def mongo(self):
        return self._mongo

    @aiohttp_jinja2.template('timeline.html')
    async def timeline(self, request):
        session = await get_session(request)
        user_id = session.get('user_id')

        if user_id is None:
            router = request.app.router
            location = router['public_timeline'].url()
            raise web.HTTPFound(location=location)

        query = {'who_id': ObjectId(user_id)}
        filter = {'whom_id': 1}
        followed = await self.mongo.follower.find_one(query, filter)
        if followed is None:
            followed = {'whom_id': []}

        query = {'$or': [{'author_id': ObjectId(user_id)},
                         {'author_id': {'$in': followed['whom_id']}}]}
        messages = await (self.mongo.message
                          .find(query)
                          .sort('pub_date', -1)
                          .to_list(30))
        endpoint = request.match_info.route.name
        return {"messages": messages,
                "endpoint": endpoint,
                "endpoint": request.match_info.route.name}

    @aiohttp_jinja2.template('timeline.html')
    async def public_timeline(self, request):
        messages = await (self.mongo.message
                          .find()
                          .sort('pub_date', -1)
                          .to_list(30))
        return {"messages": messages,
                "endpoint": request.match_info.route.name}

    @aiohttp_jinja2.template('timeline.html')
    async def user_timeline(self, request):
        username = request.match_info['username']
        profile_user = await self.mongo.user.find_one({'username': username})
        if profile_user is None:
            raise web.HTTPNotFound()
        followed = False
        session = await get_session(request)
        user_id = session.get('user_id')
        if user_id:
            followed = await self.mongo.follower.find_one(
                {'who_id': ObjectId(session['user_id']),
                 'whom_id': {'$in': [ObjectId(profile_user['_id'])]}})
            followed = followed is not None

        messages = await (self.mongo.message
                          .find({'author_id': ObjectId(profile_user['_id'])})
                          .sort('pub_date', -1)
                          .to_list(30))

        return {"messages": messages,
                "followed": followed,
                "profile_user": profile_user,
                "endpoint": request.match_info.route.name}



#@<EMAIL>.route('/<username>')
#def user_timeline(username):
#    """Display's a users tweets."""
#    profile_user = mongo.db.user.find_one({'username': username})
#    if profile_user is None:
#        abort(404)
#    followed = False
#    if g.user:
#        followed = mongo.db.follower.find_one(
#            {'who_id': ObjectId(session['user_id']),
#             'whom_id': {'$in': [ObjectId(profile_user['_id'])]}}) is not None
#    messages = mongo.db.message.find(
#        {'author_id': ObjectId(profile_user['_id'])}).sort('pub_date', -1)
#    return render_template('timeline.html', messages=messages,
#                           followed=followed, profile_user=profile_user)

    @aiohttp_jinja2.template('timeline.html')
    async def login(self, request):
        return {}
{'fraction_non_alphanumeric': 0.12963229992790196, 'fraction_numerical': 0.005479452054794521, 'mean_word_length': 2.2426367461430576, 'pattern_counts': {'":': 16, '<': 7, '<?xml version=': 0, '>': 7, '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': '2250833', 'n_tokens_mistral': 2109, 'n_tokens_neox': 2051, 'n_words': 416}