Exemple #1
0
    def __init__(self, handler_input):
        self._dataMan = kilian_data.KilianDataManager()
        self._dbEntry = {}
        self._handlerInput = handler_input
        self._sessionAttributes = {}
        self._userId = None
        self.slots = {}

        self.populateAttrs()
        self.populateDbEntry()
Exemple #2
0
    def __init__(self, dayName):
        self._holyDay = None
        self._title = None
        self.date = None
        self.dayEnum = None
        self.dayName = None

        self.dataManager = kilian_data.KilianDataManager()
        self.daySpoken = dayName
        self.resolveDayFromName(dayName)
Exemple #3
0
def getParishPhoneResponse():
    """Generate spoken response to phone number query"""
    speech = "The phone number for the Saint Kilian Parish Office is, "

    dataManager = kilian_data.KilianDataManager()
    number = dataManager.getParishOfficePhoneNumber()
    speech += ", ".join(number)
    reprompt = "Try asking: when is the next Mass."
    title = "Parish Office Phone Number"

    prettyNumber = "+1.{}.{}.{}".format(number[:3], number[3:6], number[6:])
    text = prettyNumber
    cardImage = None
    return speech, reprompt, title, text, cardImage
Exemple #4
0
    def getNextMass(self):
        """Gets the first mass that takes place today after now.

        This assumes a timezone of America/Los_Angeles (a safe assumption
        given the location of the parish).

        Returns:
            dict or None
            If there are no masses, this returns None; otherwise it returns a
            the chosen Mass along with the language that it will be given in.

        """
        dataManager = kilian_data.KilianDataManager()
        today = datetime.datetime.now(tz=pytz.utc)
        timezone = pytz.timezone("America/Los_Angeles")
        todayLocal = today.astimezone(timezone)
        todayNum = todayLocal.weekday()
        times = dataManager.getMassTimesByEnum(todayNum)
        if not times:
            # No Masses take place on this day at all.
            return None
        # Grab the last mass and compare it to now. If it's after now, then we
        #  are too late -- we've missed all of the Masses today.
        lastMassTime = times[-1][0]
        nowTime = todayLocal.time()
        LOGGER.info("Mass today?({}), at {}".format(todayNum, nowTime))
        if nowTime > lastMassTime:
            LOGGER.info("No more masses today({}), at {}".format(
                todayNum, nowTime
            ))
            return None

        # Iterate through the Masses looking for the first one that is after
        #  now.
        language = "english"
        i = 0
        bestMass = times[i][0]
        while nowTime > bestMass:
            i += 1
            bestMass = times[i][0]
            language = times[i][1]
        print("-- Chosen Mass {} ({})".format(bestMass, language))
        return {"time": bestMass, "language": language}
Exemple #5
0
    def getNextConfession(self):
        """Forms the response for confession dates and times.

        Returns:
            str, str, str, str, None
            The speech to speak, the reprompt speech to speak after a timeout,
            the title to display on a card, the text to display on a card,
            the cardImage which is None in our case.

        Raises:
            N/A

        """
        dataManager = kilian_data.KilianDataManager()
        items = dataManager.getConfessions()
        LOGGER.info("items found: {}".format(items))

        speech = "The sacrament of reconciliation will be available, "
        displayText = ""

        for item in items:
            speech += item[0]["dayName"] + ", "
            displayText += "<u>{}</u><br/>".format(item[0]["dayName"])
            for timeStr in item[0]["eventTimes"]:
                cTime = datetime.time(
                    int(timeStr.split(",")[0]),
                    int(timeStr.split(",")[1])
                )
                speech += cTime.strftime("%I:%M %p")
                displayText += "{}<br/>".format(cTime.strftime("%-I:%M %p"))
                speech += ", "
            displayText += "<br/>"

        speech += "."
        reprompt = "What else can I help you with? "
        title = "Confession"
        text = speech
        cardImage = Image(
            small_image_url="https://st-killian-resources.s3.amazonaws.com/displayTemplateMedia/rosary_340.jpg",
            large_image_url="https://st-killian-resources.s3.amazonaws.com/displayTemplateMedia/rosary_340.jpg",
        )
        return speech, reprompt, title, text, cardImage, displayText
Exemple #6
0
    def handle(self, handler_input):
        """Handle the request.

        We need to know the track that was playing last. We can give it
        an offset of zero, ensuring that it plays from the beginning as
        requested. We then need to build and deliver the directive.

        Ends session as is required by the AudioPlayer.

        Args:
            handler_input (ask_sdk_core.handler_input.HandlerInput):
                Input from Alexa.

        """
        userId = handler_input.request_envelope.context.system.user.user_id
        dataMan = kilian_data.KilianDataManager()
        dbEntry = dataMan.getUserDatabaseEntry(userId)
        track = dbEntry.get("lastTrack")
        token = dbEntry.get("lastToken")
        if not track:
            LOGGER.info("No lastTrack found in database! Can't start over.")
            return {}
        LOGGER.info("Starting over, track: {}".format(track))

        offsetInMilliseconds = 0

        directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(
                expected_previous_token=None,
                token=token,
                url=track,
                offset_in_milliseconds=offsetInMilliseconds),
                                 metadata=AudioItemMetadata(
                                     title="Latest Homily",
                                     subtitle="Latest Homily",
                                 )))
        handler_input.response_builder.add_directive(directive)
        handler_input.response_builder.set_should_end_session(True)
        return handler_input.response_builder.response
    def getLatestTalk(self):
        """Determine the latest recorded talk & return a directive for it."""
        dataMan = kilian_data.KilianDataManager()
        talk = dataMan.getLatestTalk()
        talkUrl = talk['url']
        token = talk['namespace']

        talkDate = datetime.date(talk["eventYear"], talk["eventMonth"], talk["eventDay"])
        speech = "Okay. Here is a talk from  "
        speech += "{}".format(talkDate.strftime("%A, %B %d, %Y"))
        title = "St. Kilian: Latest Talk"
        text = talk['eventTitle']

        self.userSession.lastToken = token
        self.userSession.lastTrack = talkUrl
        self.userSession.savePersistentAttrs()

        sessionAttrs = {
            "lastTrack": talkUrl,
            "lastToken": token
        }

        directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(
                stream=Stream(
                    expected_previous_token=None,
                    token=token,
                    url=talkUrl,
                    offset_in_milliseconds=0
                ),
                metadata=AudioItemMetadata(
                    title="Latest Talk",
                    subtitle=text
                )
            )
        )
        return speech, title, text, directive, sessionAttrs
Exemple #8
0
    def getNextEvents(self, numEvents=3):
        """Asks the datamanager for calendar events this month.

        If no events are found for the month, this asks for any events coming
        in the next month.

        Args:
            numEvents (int): An optional variable that specifies the number of
                events to fetch. Defaults to 3.

        Returns:
            str, str, str, str, None
            The speech to speak, the reprompt speech to speak after a timeout,
            the title to display on a card, the text to display on a card,
            the cardImage which is None in our case.

        Raises:
            N/A

        """


        dataManager = kilian_data.KilianDataManager()
        items = dataManager.getCalendarEvents()
        if not items:
            items = dataManager.getCalendarEvents(monthOffset=1)
        LOGGER.info("items found: {}".format(items))

        if len(items) > numEvents:
            items = items[:numEvents]

        if len(items) == 1:
            phrase = "event is"
        else:
            phrase = "{} events are".format(len(items))

        speech = "The next {}, ".format(phrase)

        for item in items:
            speech += item[0]["eventTitle"]
            speech += ", on "
            eventDate = item[1].strftime("%A, %B %d")
            speech += "{}, ".format(eventDate)
            if "eventTimeEnd" in item[0]:
                eventEndTime = datetime.datetime(
                    item[0]["eventYear"],
                    item[0]["eventMonth"],
                    item[0]["eventDay"],
                    int(item[0]["eventTimeEnd"].split(":")[0]),
                    int(item[0]["eventTimeEnd"].split(":")[1])
                )
                eventEndTime = eventEndTime.strftime("%I:%M %p")
                speech += "from {} to {}. ".format(eventTime, eventEndTime)
            else:
                eventTime = item[1].strftime("%I:%M %p")
                speech += "at {}. ".format(eventTime)

        reprompt = "What else can I help you with? "
        title = "Upcoming Events"
        text = speech
        cardImage = None
        return speech, reprompt, title, text, cardImage