<commit_before># -*- coding: utf-8 -*-

from __future__ import absolute_import

from django.http import HttpResponse
from django.views.generic.base import View


from icalendar import Calendar, Event

from wanikani.core import WaniKani, Radical, Kanji


class WaniKaniView(View):
    def get(self, request, **kwargs):
        client = WaniKani(kwargs['api_key'])

        level = client.profile()['level']
        queue = client.query(level, items=[Radical, Kanji], include=[u'apprentice'])

        cal = Calendar()
        cal.add('prodid', '-//Wanikani Blockers//github.com/kfdm/wanikani//')
        cal.add('version', '2.0')

        for ts in sorted(queue):
            if not len(queue[ts]):
                continue

            counts = {
                Radical: 0,
                Kanji: 0,
            }

            for obj in queue[ts]:
                counts[obj.__class__] += 1

            event = Event()
            if counts[Radical] and counts[Kanji]:
                event.add('summary', u'部首: {0} 漢字: {1}'.format(
                    counts[Radical], counts[Kanji]
                ))
            elif counts[Radical]:
                event.add('summary', u'部首: {0}'.format(
                    counts[Radical]
                ))
            else:
                event.add('summary', u'漢字: {0}'.format(
                    counts[Kanji]
                ))
            event.add('dtstart', ts)
            event.add('dtend', ts)
            event['uid'] = str(ts)

            cal.add_component(event)

        return HttpResponse(
            content=cal.to_ical(),
            content_type='text/plain; charset=utf-8'
        )
<commit_msg>Minor adjustment to django view<commit_after># -*- coding: utf-8 -*-

from __future__ import absolute_import

from django.conf.urls import patterns, url
from django.http import HttpResponse
from django.views.generic.base import View

from icalendar import Calendar, Event

from wanikani.core import WaniKani, Radical, Kanji


class WaniKaniView(View):
    def get(self, request, **kwargs):
        client = WaniKani(kwargs['api_key'])

        level = client.profile()['level']
        queue = client.query(level, items=[Radical, Kanji], include=[u'apprentice'])

        cal = Calendar()
        cal.add('prodid', '-//Wanikani Blockers//github.com/kfdm/wanikani//')
        cal.add('version', '2.0')

        for ts in sorted(queue):
            if not len(queue[ts]):
                continue

            counts = {
                Radical: 0,
                Kanji: 0,
            }

            for obj in queue[ts]:
                counts[obj.__class__] += 1

            event = Event()
            if counts[Radical] and counts[Kanji]:
                event.add('summary', u'部首: {0} 漢字: {1}'.format(
                    counts[Radical], counts[Kanji]
                ))
            elif counts[Radical]:
                event.add('summary', u'部首: {0}'.format(
                    counts[Radical]
                ))
            else:
                event.add('summary', u'漢字: {0}'.format(
                    counts[Kanji]
                ))
            event.add('dtstart', ts)
            event.add('dtend', ts)
            event['uid'] = str(ts)

            cal.add_component(event)

        return HttpResponse(
            content=cal.to_ical(),
            content_type='text/plain; charset=utf-8'
        )

urlpatterns = patterns(
    '',
    url(r'^(?P<api_key>\w+)', WaniKaniView.as_view()),
)

{'fraction_non_alphanumeric': 0.13118527042577677, 'fraction_numerical': 0.006329113924050633, 'mean_word_length': 1.6725595695618756, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '874100', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1026, 'n_words': 219}