<commit_before>import time
import urllib
from BeautifulSoup import BeautifulSoup

import thing
import command

#TODO:
#      Get rid of course command syntax? maybe?
#      Add error handing to webpage fetching.
#      Search with different keys.

@thing.facet_classes.register
class ScheduleFacet(thing.ThingFacet):
    name = "course"
    commands = command.thing.add_child(command.FacetCommandSet(name))
    URL = "http://cs.pdx.edu/schedule/termschedule?"
    SECONDS_PER_HOUR = 60 * 60

    def on_attach(self):
        self.last_retrieval_time = {}
        self.sched = {}

    @commands.add(u"{thing} {CSXXX} {TERM} {YEAR}", help=u"Get course information.")
    def course1(self, thing, CSXXX, TERM, YEAR, context):
        sched_key = TERM + YEAR
        def to_str(item):
            if item is None:
                return ""
            else:
                return item + " "
        def format_course(course):
            return to_str(course["CRN"]) +\
                   to_str(course["Title"]) +\
                   to_str(course["Faculty"]) +\
                   to_str(course["Days"]) +\
                   to_str(course["Time"]) +\
                   to_str(course["Bldg"]) +\
                   to_str(course["Room"])
        cur_time = time.time()<commit_msg>Initial port of the schedule plugin to the new KB API. Currently broken.<commit_after>import time
import urllib
from BeautifulSoup import BeautifulSoup

from karmabot.core.client import thing
from karmabot.core.thing import ThingFacet
from karmabot.core.register import facet_registry, presenter_registry
from karmabot.core.commands.sets import CommandSet

#TODO:
#      Get rid of course command syntax? maybe?
#      Add error handing to webpage fetching.
#      Search with different keys.

@facet_registry.register
class ScheduleFacet(ThingFacet):
    name = "course"
    commands = thing.add_child(CommandSet(name))
    URL = "http://cs.pdx.edu/schedule/termschedule?"
    SECONDS_PER_HOUR = 60 * 60

    def on_attach(self):
        self.last_retrieval_time = {}
        self.sched = {}

    @commands.add(u"course {CSXXX} {TERM} {YEAR}", u"Get course information from CS website.")
    def course1(self, context, CSXXX, TERM, YEAR):
        sched_key = TERM + YEAR
        def to_str(item):
            if item is None:
                return ""
            else:
                return item + " "
        def format_course(course):
            return to_str(course["CRN"]) +\
                   to_str(course["Title"]) +\
                   to_str(course["Faculty"]) +\
                   to_str(course["Days"]) +\
                   to_str(course["Time"]) +\
                   to_str(course["Bldg"]) +\
                   to_str(course["Room"])
        cur_time = time.time()
{'fraction_non_alphanumeric': 0.11283905967450271, 'fraction_numerical': 0.003616636528028933, 'mean_word_length': 2.220023282887078, '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': '2995613', 'n_tokens_mistral': 858, 'n_tokens_neox': 810, 'n_words': 196}