<commit_before># coding: utf-8

# maposmatic, the web front-end of the MapOSMatic city map generation system
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Feeds for MapOSMatic

import datetime
import logging

LOG = logging.getLogger('maposmatic')

from django.contrib.gis.feeds import Feed
from django.utils.translation import ugettext_lazy as _
from django.template.loader import render_to_string, get_template

from www.maposmatic import models
import www.settings

class MapsFeed(Feed):
    """
    This feeds syndicates the latest successfully rendered maps in MapOSMatic,
    with their thumbnail, and links to the rendered files.
    """

    title = "%s %s %s" % (www.settings.BRAND_NAME, _("maps"), 
                          www.settings.DEBUG and _('') or _('[DEV]'))
    link = '/maps/' # We can't use reverse here as the urlpatterns aren't
                    # defined yet at this point.
    description = _('The latest rendered maps on MapOSMatic.')

    description_template = "maposmatic/map-feed.html"

    def items(self):
        """Returns the successfully rendered maps from the last 24 hours, or
        the last 10 maps/jobs if nothing happened recently."""

        one_day_before = datetime.datetime.now() - datetime.timedelta(1)
        items = (models.MapRenderingJob.objects
                 .filter(status=2)
                 .filter(resultmsg='ok')
                 .filter(endofrendering_time__gte=one_day_before)
                 .order_by('-endofrendering_time'))

        if items.count():
            return items

        # Fall back to the last 10 entries, regardless of time
        return (models.MapRenderingJob.objects
                .filter(status=2)
                .filter(resultmsg='ok')
                .order_by('-endofrendering_time')[:10])

        # Not sure what to do if we still don't have any items at this point.

    def item_title(self, item):
        return "#%d - %s" % (item.id, item.maptitle)

    def item_geometry(self, item):
        if item.administrative_city:
            return None
        else:
            return (item.lon_upper_left, item.lat_upper_left,
                    item.lon_bottom_right, item.lat_bottom_right)

    def item_pubdate(self, item):<commit_msg>set placeholder for empty title in rss feed<commit_after># coding: utf-8

# maposmatic, the web front-end of the MapOSMatic city map generation system
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>
# Copyright (C) 2010  <NAME>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Feeds for MapOSMatic

import datetime
import logging

LOG = logging.getLogger('maposmatic')

from django.contrib.gis.feeds import Feed
from django.utils.translation import ugettext_lazy as _
from django.template.loader import render_to_string, get_template

from www.maposmatic import models
import www.settings

class MapsFeed(Feed):
    """
    This feeds syndicates the latest successfully rendered maps in MapOSMatic,
    with their thumbnail, and links to the rendered files.
    """

    title = "%s %s %s" % (www.settings.BRAND_NAME, _("maps"), 
                          www.settings.DEBUG and _('') or _('[DEV]'))
    link = '/maps/' # We can't use reverse here as the urlpatterns aren't
                    # defined yet at this point.
    description = _('The latest rendered maps on MapOSMatic.')

    description_template = "maposmatic/map-feed.html"

    def items(self):
        """Returns the successfully rendered maps from the last 24 hours, or
        the last 10 maps/jobs if nothing happened recently."""

        one_day_before = datetime.datetime.now() - datetime.timedelta(1)
        items = (models.MapRenderingJob.objects
                 .filter(status=2)
                 .filter(resultmsg='ok')
                 .filter(endofrendering_time__gte=one_day_before)
                 .order_by('-endofrendering_time'))

        if items.count():
            return items

        # Fall back to the last 10 entries, regardless of time
        return (models.MapRenderingJob.objects
                .filter(status=2)
                .filter(resultmsg='ok')
                .order_by('-endofrendering_time')[:10])

        # Not sure what to do if we still don't have any items at this point.

    def item_title(self, item):
        title = item.maptitle
        if not title:
            title = "(untitled)"
        return "#%d - %s" % (item.id, title)

    def item_geometry(self, item):
        if item.administrative_city:
            return None
        else:
            return (item.lon_upper_left, item.lat_upper_left,
                    item.lon_bottom_right, item.lat_bottom_right)

    def item_pubdate(self, item):
{'fraction_non_alphanumeric': 0.08817343471930109, 'fraction_numerical': 0.013266461737582915, 'mean_word_length': 2.7580547112462006, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, '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': '3065820', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1707, 'n_words': 641}