Exemplo n.º 1
0
def parseArgs(day):
    semester = int(config.get("semester"))
    year = int(config.get("year"))
    years_counter = int(config.get("years"))
    # Check if a schedule or a day was called
    if len(day) == 0:
        day = []
    else:
        # Only either of them was passed
        if len(day) == 1:
            # Called a schedule
            if day[0].isdigit():
                if 0 < int(day[0]) < years_counter + 1:
                    year = int(day[0])
                    day = []
                else:
                    return [False, "Dit is geen geldige jaargang."]
            # elif: calling a weekday is automatically handled below,
            # so checking is obsolete
        else:
            # TODO check other direction (di 1) in else
            # Both were passed
            if day[0].isdigit():
                if 0 < int(day[0]) < years_counter + 1:
                    year = int(day[0])
                    # day = []
                else:
                    return [False, "Dit is geen geldige jaargang."]
            # Cut the schedule from the string
            day = day[1:]
    day = getWeekDay(None if len(day) == 0 else day)[1]
    dayDatetime = findDate(timeFormatters.weekdayToInt(day))

    return [True, day, dayDatetime, semester, year]
Exemplo n.º 2
0
    async def les(self, ctx, *day):
        semester = int(config.get("semester"))
        year = int(config.get("year"))
        years_counter = int(config.get("years"))
        # Check if a schedule or a day was called
        if len(day) == 0:
            day = []
        else:
            # Only either of them was passed
            if len(day) == 1:
                # Called a schedule
                if day[0].isdigit():
                    if 0 < int(day[0]) < years_counter + 1:
                        year = int(day[0])
                        day = []
                    else:
                        return await ctx.send("Dit is geen geldige jaargang.")
                # elif: calling a weekday is automatically handled below,
                # so checking is obsolete
            else:
                # Both were passed
                if day[0].isdigit():
                    if 0 < int(day[0]) < years_counter + 1:
                        year = int(day[0])
                        day = []
                    else:
                        return await ctx.send("Dit is geen geldige jaargang.")
                # Cut the schedule from the string
                day = day[1:]

        day = self.getWeekDay(None if len(day) == 0 else day)[1]
        dayDatetime = self.findDate(timeFormatters.weekdayToInt(day))

        schedule = self.customizeSchedule(ctx, year, semester)

        # Create a date object to check the current week
        startDate = 1600041600
        currentTime = dayDatetime.timestamp()
        week = clamp(
            timeFormatters.timeIn(currentTime - startDate, "weeks")[0], 1, 13)

        title, week = self.getTitle(day, dayDatetime, week)

        # Add all courses & their corresponding times + locations of today
        courses, extras, prev, online = self.getCourses(schedule, day, week)

        embed = discord.Embed(colour=discord.Colour.blue(), title=title)
        embed.set_author(name="Lessenrooster voor {}{} Bachelor".format(
            year, "ste" if year == 1 else "de"))

        if len(courses) == 0:
            embed.add_field(name="Geen Les", value="Geen Les", inline=False)
        else:
            courseString = self.createCourseString(courses)
            courseString += "\nGroep {} heeft vandaag online les.".format(
                1 if week % 2 == 0 else 2)
            embed.description = courseString

            if prev:
                embed.add_field(name="Vakken uit vorige jaren",
                                value=self.createCourseString(prev),
                                inline=False)

            if extras:
                embed.add_field(name="Extra",
                                value="\n".join(
                                    self.getExtras(extra) for extra in extras),
                                inline=False)

            # Add online links if not commnet
            if online:
                embed.add_field(name="Online Links",
                                value="\n".join(
                                    self.getLink(onlineClass)
                                    for onlineClass in online))

            embed.set_footer(
                text="Semester  {} | Lesweek {}".format(semester, round(week)))
        await ctx.send(embed=embed)