示例#1
0
def what_meds_taken_intent():
    """State which meds have been taken"""
    session = db.Session()
    user_id = get_id(request)
    meds = session.query(db.Med).filter_by(account_id=user_id)

    if not meds:
        session.close()
        return statement("I'm not tracking any medications for you.")

    meds_taken = [m.name for m in meds if m.is_taken_today()]
    session.close()

    if len(meds_taken) == 0:
        return statement(
            "You haven't told me that you've taken any medications.")
    if len(meds_taken) == 1:
        return statement(f"You've told me that you've taken {meds_taken[0]}")
    if len(meds_taken) == 2:
        return statement(
            f"You've told me that you've taken {meds_taken[0]} and {meds_taken[1]}"
        )
    if len(meds_taken) > 2:
        return_statement = "You've told me that you've taken " + ", ".join(
            meds_taken[:-1]) + f", and {meds_taken[-1]}"
        return statement(return_statement)
    def createConference(self):
        self.getJSON()
        if not self._json:
            logging.info('Cant create')
            return
        self._conference = data.Conference()
        talks = self._json['feed']['entry']
        for talk in talks:
            id = getSpreadsheetFieldValue(talk, 'sessionhashtag')
            day = getSpreadsheetFieldValue(talk, 'sessiondate')
            time = getSpreadsheetFieldValue(talk, 'sessiontime')
            location = 'Room #%s' % getSpreadsheetFieldValue(talk, 'room')
            talk_name = getSpreadsheetFieldValue(talk, 'sessiontitle')
            if talk_name:
                talk_name = talk_name.strip('\n')
            talk_link = getSpreadsheetFieldValue(talk, 'sessionlink')
            talk_description = getSpreadsheetFieldValue(
                talk, 'sessionabstract')
            talk_reqs = getSpreadsheetFieldValue(talk, 'sessionrequirements')
            waveid = getSpreadsheetFieldValue(talk, 'waveid')
            type = getSpreadsheetFieldValue(talk, 'sessiontype')
            track = getSpreadsheetFieldValue(talk, 'track')
            tags_raw = getSpreadsheetFieldValue(talk, 'tags')
            tags = []
            # Split comma separated list
            if tags:
                tags = tags.split(',')
            # Remove whitespace
            for tag in tags:
                tag = tag.strip()

            speakers = []
            speakers_raw = getSpreadsheetFieldValue(
                talk, 'sessionspeakers').split(',')
            for speaker in speakers_raw:
                speaker_name = speaker.strip()
                base_url = 'http://code.google.com/events/io/2010/speakers.html'
                speaker_link = '%s#%s' % (base_url,
                                          speaker_name.replace(' ', ''))
                speaker = data.Speaker(speaker_name, link=speaker_link)
                speakers.append(speaker)

            session = data.Session(id=id,
                                   day=day,
                                   time=time,
                                   location=location,
                                   name=talk_name,
                                   link=talk_link,
                                   description=talk_description,
                                   prereqs=talk_reqs,
                                   track=track,
                                   hashtag=id,
                                   tags=tags,
                                   speakers=speakers,
                                   type=type,
                                   waveid=waveid)
            self._conference.sessions.append(session)
示例#3
0
def take_med_intent(med_name):
    session = db.Session()
    user_id = get_id(request)

    med = db.get_med(session, user_id, med_name)

    if not med:
        session.close()
        return statement(
            f"I'm not tracking {med_name}. Let me know if you want to start tracking it."
        )

    med.take()
    session.commit()
    return statement(f"Okay, you've taken {med_name}.")
示例#4
0
def remove_med_intent(med_name):
    """Tell the skill to remove a med from your account"""
    session = db.Session()
    user_id = get_id(request)

    med = db.get_med(session, user_id, med_name)

    if not med:
        session.close()
        return statement(f"I wasn't tracking {med_name}.")

    session.delete(med)
    session.commit()

    return statement(f"I'm no longer keeping track of {med_name}.")
示例#5
0
def add_med_intent(med_name):
    """Tell the skill to add a med to your account"""
    session = db.Session()
    user_id = get_id(request)

    # See if the med is already there
    med = db.get_med(session, user_id, med_name)

    if med:
        return statement(f"I'm already tracking {med_name} for you.")

    new_med = db.Med(account_id=user_id, name=med_name, when_taken=0.0)
    session.add(new_med)
    session.commit()

    return statement(f"I'm now tracking {med_name} for you")
示例#6
0
def ask_med_intent(med_name):
    """Ask the skill if you took a med"""
    session = db.Session()
    user_id = get_id(request)

    med = db.get_med(session, user_id, med_name)

    if not med:
        session.close()
        return statement(f"I'm not tracking {med_name}.")

    is_taken = med.is_taken_today()
    session.close()

    if is_taken:
        return statement(f"You did take {med_name}")
    else:
        return statement(f"You haven't taken {med_name} today")
示例#7
0
def take_two_med_intent(med_name, med_name_2):
    """Tell the skill you want to take a med"""
    session = db.Session()
    user_id = get_id(request)
    med_names = [med_name, med_name_2]

    meds = [db.get_med(session, user_id, med) for med in med_names]

    if not all(meds):
        session.close()
        return statement(
            "I didn't recognize one of those medications, so I didn't record anything"
        )

    for med in meds:
        med.take()

    session.commit()
    return statement(f"Okay, you've taken {med_name} and {med_name_2}")
示例#8
0
def cancel_med_intent(med_name):
    """Tell the skill that you didn't actually take a med"""
    session = db.Session()
    user_id = get_id(request)

    med = db.get_med(session, user_id, med_name)

    if not med:
        session.close()
        return statement(f"I wasn't tracking {med_name}.")

    taken_today = med.is_taken_today()

    if not taken_today:
        session.close()
        return statement(f"It seems you didn't take {med_name} anyway.")

    med.when_taken = 0.0
    session.commit()
    return statement(f"Okay, you didn't take {med_name}")
示例#9
0
 def createConference(self):
   self.getJSON()
   if not self._json:
     logging.info('Cant create')
     return
   self._conference  = data.Conference()
   talks = self._json['feed']['entry']
   for talk in talks:
     id = getSpreadsheetFieldValue(talk, 'id')
     day = getSpreadsheetFieldValue(talk, 'day')
     time = getSpreadsheetFieldValue(talk, 'time')
     location = getSpreadsheetFieldValue(talk, 'location')
     talk_name = getSpreadsheetFieldValue(talk, 'talkname')
     talk_link = getSpreadsheetFieldValue(talk, 'talklink')
     talk_description = getSpreadsheetFieldValue(talk, 'talkdescription')
     speaker_name = getSpreadsheetFieldValue(talk, 'speakername')
     speaker_link = getSpreadsheetFieldValue(talk, 'speakerlink')
     speaker_description = getSpreadsheetFieldValue(talk, 'speakerdescription')
     speaker = data.Speaker(speaker_name, link=speaker_link,
                            description=speaker_description)
     session = data.Session(id=id, day=day, time=time, location=location,
                            name=talk_name, link=talk_link, description=talk_description,
                            speakers=[speaker])
     self._conference.sessions.append(session)
示例#10
0
 async def pins_channel(self, ctx, channel: discord.TextChannel = None):
     """Sets the pin archive channel of the server."""
     session = data.Session()
     pin_archive = session.query(PinArchive).get(ctx.guild.id)
     if channel is not None:
         if pin_archive:
             pin_archive.channel_id = channel.id
         else:
             pin_archive = PinArchive(server_id=ctx.guild.id,
                                      channel_id=channel.id)
             session.add(pin_archive)
         session.commit()
         session.close()
         embed = self.bot.generate_embed(
             '✅',
             f'Ustawiono #{channel} jako kanał archiwum przypiętych wiadomości'
         )
     else:
         if pin_archive is not None and pin_archive.channel_id is not None:
             notice = f'Kanałem archiwum przypiętych wiadomości jest #{pin_archive.discord_channel(self.bot)}'
         else:
             notice = 'Nie ustawiono na serwerze kanału archiwum przypiętych wiadomości'
         embed = self.bot.generate_embed('🗃️', notice)
     await self.bot.send(ctx, embed=embed)