<commit_before>from datetime import datetime
from urlparse import urljoin

from flask import Blueprint, render_template, abort, request, url_for
from werkzeug.contrib.atom import AtomFeed

from been import Been


blueprint = Blueprint('wake', __name__)


been = blueprint.been = Been()
store = blueprint.store = been.store


@blueprint.app_template_filter('relativetime')
def relative_time(timestamp):
    delta = (datetime.now() - datetime.fromtimestamp(timestamp))
    delta_s = delta.days * 86400 + delta.seconds
    if delta_s < 60:
        return "less than a minute ago"
    elif delta_s < 120:
        return "about a minute ago"
    elif delta_s < (60 * 60):
        return str(delta_s / 60) + " minutes ago"
    elif delta_s < (120 * 60):
        return "about an hour ago"
    elif delta_s < (24 * 60 * 60):
        return "about " + str(delta_s / 3600) + " hours ago"
    elif delta_s < (48 * 60 * 60):
        return "1 day ago"
    else:
        return str(delta_s / 86400) + " days ago"


@blueprint.route('/')
def index():
    return render_template('stream.html', events=store.collapsed_events())


@blueprint.route('/post/<slug>')
def by_slug(slug):
    events = list(store.events_by_slug(slug))
    if not events:
        abort(404)
    return render_template('stream.html', events=events)


@blueprint.route('/recent.atom')
def recent_feed():
    feed = AtomFeed('Recent Posts', feed_url=request.url, url=request.url_root,
                    generator=('Wake', None, None))
    sources = store.get_sources()
    for event in store.events():
        if sources[event['source']].get('syndicate'):
            feed.add(event['title'],
                     unicode(event['content']),
                     content_type='html',
                     author=event.get('author', ''),
                     url=urljoin(request.url_root, url_for('by_slug', slug=event.get('slug', ''))),
                     updated=datetime.fromtimestamp(event['timestamp']),
                     published=datetime.fromtimestamp(event['timestamp']))
    return feed.get_response()<commit_msg>Fix Atom syndication to aggregate syndicated sources individually.<commit_after>from datetime import datetime
from urlparse import urljoin

from flask import Blueprint, render_template, abort, request, url_for
from werkzeug.contrib.atom import AtomFeed

from been import Been


blueprint = Blueprint('wake', __name__)


been = blueprint.been = Been()
store = blueprint.store = been.store


@blueprint.app_template_filter('relativetime')
def relative_time(timestamp):
    delta = (datetime.now() - datetime.fromtimestamp(timestamp))
    delta_s = delta.days * 86400 + delta.seconds
    if delta_s < 60:
        return "less than a minute ago"
    elif delta_s < 120:
        return "about a minute ago"
    elif delta_s < (60 * 60):
        return str(delta_s / 60) + " minutes ago"
    elif delta_s < (120 * 60):
        return "about an hour ago"
    elif delta_s < (24 * 60 * 60):
        return "about " + str(delta_s / 3600) + " hours ago"
    elif delta_s < (48 * 60 * 60):
        return "1 day ago"
    else:
        return str(delta_s / 86400) + " days ago"


@blueprint.route('/')
def index():
    return render_template('stream.html', events=store.collapsed_events())


@blueprint.route('/post/<slug>')
def by_slug(slug):
    events = list(store.events_by_slug(slug))
    if not events:
        abort(404)
    return render_template('stream.html', events=events)


@blueprint.route('/recent.atom')
def recent_feed():
    entries = []
    for source_id, source in store.get_sources().iteritems():
        if not source.get('syndicate'):
            continue

        for event in store.events(source=source_id):
            entries.append({
                'title': event['title'],
                'content': unicode(event['content']),
                'content_type': 'html',
                'author': event.get('author', ''),
                'url': urljoin(request.url_root,
                               url_for('by_slug', slug=event.get('slug', ''))),
                'updated': datetime.fromtimestamp(event['timestamp']),
                'published': datetime.fromtimestamp(event['timestamp']),
            })

    entries.sort(key=lambda e: e['published'], reverse=True)

    feed = AtomFeed('Recent Posts', feed_url=request.url, url=request.url_root,
                    generator=('Wake', None, None))
    for entry in entries:
        feed.add(**entry)
    return feed.get_response()
{'fraction_non_alphanumeric': 0.1299598751671868, 'fraction_numerical': 0.02050824788230049, 'mean_word_length': 2.7928994082840237, 'pattern_counts': {'":': 0, '<': 17, '<?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': '4281075', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1331, 'n_words': 333}