<commit_before># -*- coding: utf-8 -*-
import os
import datetime
import rfc822

from flask import (Flask, send_from_directory, render_template, make_response,
                   abort)
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import orm, func

from rtrss.models import Topic, Category, Torrent
from rtrss.filestorage import make_storage
from rtrss import config


app = Flask(__name__)
app.config.from_object('rtrss.config')
db = SQLAlchemy(app)

MIN_TTL = 30  # minutes
MAX_TTL = 1440  # 1 day


@app.route('/')
def index():
    tree = make_category_tree()
    return render_template('index.html', tree=tree)


@app.route('/torrent/<int:torrent_id>')
def torrent(torrent_id):
    # TODO add user passkey support
    storage = make_storage(config)
    torrentfile = storage.get(config.TORRENT_PATH_PATTERN.format(torrent_id))

    if torrentfile:
        fn = '{}.torrent'.format(torrent_id)
        resp = make_response(torrentfile)
        resp.headers['Content-Type'] = 'application/x-bittorrent'
        resp.headers['Content-Disposition'] = 'attachment; filename=' + fn
        return resp
    else:
        abort(404)


@app.route('/feed/', defaults={'category_id': 0})
@app.route('/feed/<int:category_id>')
def feed(category_id=0):
    feed_data = get_feed_data(category_id)

    content = render_template(
        'feed.xml',
        channel=feed_data['channel'],
        items=feed_data['items']
    ).encode('utf-8')
    response = make_response(content)
    response.headers['content-type'] = 'application/rss+xml; charset=UTF-8'
    return response


@app.route('/favicon.ico')
def favicon():
    return send_from_directory(
        os.path.join(app.root_path, 'static'),
        'favicon.ico', mimetype='image/vnd.microsoft.icon')
<commit_msg>Implement ping method<commit_after># -*- coding: utf-8 -*-
import os
import datetime
import rfc822

from flask import (Flask, send_from_directory, render_template, make_response,
                   abort)
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import orm, func

from rtrss.models import Topic, Category, Torrent
from rtrss.filestorage import make_storage
from rtrss import config


app = Flask(__name__)
app.config.from_object('rtrss.config')
db = SQLAlchemy(app)

MIN_TTL = 30  # minutes
MAX_TTL = 1440  # 1 day


@app.route('/')
def index():
    tree = make_category_tree()
    return render_template('index.html', tree=tree)


@app.route('/torrent/<int:torrent_id>')
def torrent(torrent_id):
    # TODO add user passkey support
    storage = make_storage(config)
    torrentfile = storage.get(config.TORRENT_PATH_PATTERN.format(torrent_id))

    if torrentfile:
        fn = '{}.torrent'.format(torrent_id)
        resp = make_response(torrentfile)
        resp.headers['Content-Type'] = 'application/x-bittorrent'
        resp.headers['Content-Disposition'] = 'attachment; filename=' + fn
        return resp
    else:
        abort(404)


@app.route('/feed/', defaults={'category_id': 0})
@app.route('/feed/<int:category_id>')
def feed(category_id=0):
    feed_data = get_feed_data(category_id)

    content = render_template(
        'feed.xml',
        channel=feed_data['channel'],
        items=feed_data['items']
    ).encode('utf-8')
    response = make_response(content)
    response.headers['content-type'] = 'application/rss+xml; charset=UTF-8'
    return response


@app.route('/favicon.ico')
def favicon():
    return send_from_directory(
        os.path.join(app.root_path, 'static'),
        'favicon.ico', mimetype='image/vnd.microsoft.icon')

@app.route('/ping')
def ping():
    return "Alive: {}".format(datetime.datetime.utcnow().isoformat())
{'fraction_non_alphanumeric': 0.1333515881708653, 'fraction_numerical': 0.009857612267250822, 'mean_word_length': 3.8256274768824308, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5647863', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1187, 'n_words': 244}