<commit_before>import datetime
import logging

from google.appengine.api import taskqueue

from base.constants import CONSTANTS
import base.handlers
import data

_FREQUENCY_DISPLAY_NAMES = {
    '1d': 'every day',
    '2d': 'every other day',
    '7d': 'every week',
}

class MainHandler(base.handlers.BaseHandler):
    def get(self):
        self._write_template('feedplayback/index.html')

class AdvanceCronHandler(base.handlers.BaseHandler):
    def get(self):
        frequency = self.request.get('frequency')
        frequency_modulo = int(self.request.get('frequency_modulo'))

        current_modulo = data.get_modulo_for_frequency(frequency)
        if current_modulo != frequency_modulo:
            logging.info('Not advancing for modulo %d today '
                '(which is modulo %d)' % (frequency_modulo, current_modulo))
            return

        subscriptions = data.get_subscriptions_with_frequency_and_modulo(
            frequency, frequency_modulo)

        for subscription in subscriptions:
            taskqueue.add(
                name='feedplayback-advance-subscription-%s' % subscription.id,
                queue_name='feedplayback-advance',
                url='/tasks/feed-playback/advance',
                params={'subscription_id': subscription.id})

        logging.info('Advanced %d subscriptions' % len(subscriptions))
        self.response.out.write('OK')

class AdvanceTaskHandler(base.handlers.BaseHandler):
    def post(self):
        subscription_id = self.request.get('subscription_id')
        subscription = data.get_subscription_by_id(subscription_id)
        subscription.advance()
        self.response.out.write('OK')

class PreviewHandler(base.handlers.BaseHandler):
    def get(self):
        url = self.request.get('url')
        try:
            start_date = datetime.datetime.strptime(
                self.request.get('start-date'), '%Y-%m-%d')
        except ValueError:
            start_date = datetime.datetime(1970, 1, 1)

        self._write_json({<commit_msg>Underscores are not allowed in task names.<commit_after>import datetime
import logging

from google.appengine.api import taskqueue

from base.constants import CONSTANTS
import base.handlers
import data

_FREQUENCY_DISPLAY_NAMES = {
    '1d': 'every day',
    '2d': 'every other day',
    '7d': 'every week',
}

class MainHandler(base.handlers.BaseHandler):
    def get(self):
        self._write_template('feedplayback/index.html')

class AdvanceCronHandler(base.handlers.BaseHandler):
    def get(self):
        frequency = self.request.get('frequency')
        frequency_modulo = int(self.request.get('frequency_modulo'))

        current_modulo = data.get_modulo_for_frequency(frequency)
        if current_modulo != frequency_modulo:
            logging.info('Not advancing for modulo %d today '
                '(which is modulo %d)' % (frequency_modulo, current_modulo))
            return

        subscriptions = data.get_subscriptions_with_frequency_and_modulo(
            frequency, frequency_modulo)

        for subscription in subscriptions:
            id_for_task_name = subscription.id.replace('_', 'UNDERSCORE')
            taskqueue.add(
                name='feedplayback-advance-%s' % id_for_task_name,
                queue_name='feedplayback-advance',
                url='/tasks/feed-playback/advance',
                params={'subscription_id': subscription.id})

        logging.info('Advanced %d subscriptions' % len(subscriptions))
        self.response.out.write('OK')

class AdvanceTaskHandler(base.handlers.BaseHandler):
    def post(self):
        subscription_id = self.request.get('subscription_id')
        subscription = data.get_subscription_by_id(subscription_id)
        subscription.advance()
        self.response.out.write('OK')

class PreviewHandler(base.handlers.BaseHandler):
    def get(self):
        url = self.request.get('url')
        try:
            start_date = datetime.datetime.strptime(
                self.request.get('start-date'), '%Y-%m-%d')
        except ValueError:
            start_date = datetime.datetime(1970, 1, 1)

        self._write_json({
{'fraction_non_alphanumeric': 0.10810157194679565, 'fraction_numerical': 0.004353083434099154, 'mean_word_length': 2.879924953095685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6172975', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1189, 'n_words': 220}