Exemple #1
0
def welcome():
    id = users.user_id()
    nimi = users.user_firstname(users.user_all(id))
    if users.is_admin(id):
        courselist = courses.get_courses()
        userlist = users.get_users()
        userlist.sort(key=lambda x: x[5])
        answerList = questions.get_answers()
        return render_template("welcome_admin.html", name = nimi, courses = courselist, \
            users = userlist, answers = answerList)
    elif users.is_teacher(id):
        course = courses.get_course_with_teacher(id)
        return render_template("welcome_teacher.html",
                               id=id,
                               name=nimi,
                               courses=course)
    elif users.is_student(id):
        mycourselist = students.get_courses(id)
        courselist = courses.get_courses()
        return render_template("welcome_student.html", id = id, name = nimi, courses = courselist,\
            mycourses = mycourselist)
    else:
        return render_template("error.html", message="Jokin meni vikaan")
Exemple #2
0
def get_codery_result(codery_keywords: str) -> str:
    help_message = "*Help for Codery*  : \n\n" \
                   "The bot responds to messages starting with @Codery.\n\n" \
                   "`@Codery contests` will return top Contests today, their dates, time left and the links to each contest.\n" \
                   "`@Codery top contest` also returns the top Contest result.\n" \
                   "`@Codery trending` returns the top trending ploblems across all programming platforms.\n" \
                   "`@Codery dictionary <search term>` returns the meaning of that word in an instant.\n" \
                   "`@Codery jokes` keeps your morale boosted with programming jokes.\n" \
                   "`@Codery jobs <searchword>` returns the top jobs for that search word.\n" \
                   "`@Codery news <keyword>` returns the news for that key word.\n" \
                   "`@Codery man <function>` returns the user manual of that function.\n" \
                   "`@Codery top <n> contests` will return n number of top contests at that time.\n \n" \
                   "Example:\n" \
                   " * @Codery contests\n" \
                   " * @Codery top contest\n" \
                   " * @Codery jokes\n" \
                   " * @Codery top 7 contests\n" \
                   " * @Codery dictionary computer\n" \
                   " * @Codery search code\n" \
                   " * @Codery jobs pyhton\n" \
                   " * @Codery jobs java\n" \
                   " * @Codery trending\n" \
                   " * @Codery man execvp\n" \
                   " * @Codery news corona"

    codery_keywords = codery_keywords.strip()
    codery_keywords_list = codery_keywords.split(" ")

    if codery_keywords == 'help':
        return help_message

    elif codery_keywords_list[0] == "todo":
        return todo.get_todo_response(codery_keywords, CoderyHandler)

    elif codery_keywords_list[0] == "jobs":
        return jobs.get_jobs(codery_keywords, CoderyHandler)

    elif codery_keywords_list[0] == "leaderboard":
        return leaderboard.get_leaderboard()

    elif codery_keywords_list[0] == "trending":
        return trendingproblems.get_problems()

    elif codery_keywords_list[0] == "search" or codery_keywords_list[
            0] == "dictionary":
        return dictionary.get_dictionary_response(codery_keywords,
                                                  CoderyHandler)

    elif codery_keywords_list[0] == "courses" or codery_keywords_list[
            0] == "course":
        return courses.get_courses(codery_keywords, CoderyHandler)

    elif codery_keywords_list[0] == "jokes" or codery_keywords_list[
            0] == "joke":
        return geekjokes.get_joke(codery_keywords, CoderyHandler)

    elif codery_keywords_list[0] == "calculator":
        return "The answer is" + calculator.get_calculator_response(
            codery_keywords, CoderyHandler)

    elif codery_keywords_list[0] == "news":
        return news.get_news_response(codery_keywords, CoderyHandler)

    elif codery_keywords == 'contests':

        URL = 'https://www.stopstalk.com/contests'
        content = requests.get(URL)
        soup = BeautifulSoup(content.text, 'html.parser')
        contentTable = soup.find('table',
                                 {"class": "centered bordered"
                                  })  # Use dictionary to pass key : value pair

        rows = contentTable.find_all('tr')
        lo = []
        i = 0

        for row in rows[1:]:
            lo.append("##")
            columns = row.find_all('td')
            for column in columns:
                if column.get_text() != "":
                    lo.append((column.get_text()).strip() + "@@")

            lo.append((columns[4].find('a')['href']).strip())
            i += 1

        l1 = "The top contests and hackathons of  today are \n"
        for r in lo:
            allContest = r.split("##")
            for eachContest in allContest:
                attrList = eachContest.split("@@")
                for attr in attrList:
                    l1 += attr + "\n"

        return l1

    # return a list of top contests
    elif codery_keywords == 'top contest':
        URL = 'https://www.stopstalk.com/contests'
        content = requests.get(URL)
        soup = BeautifulSoup(content.text, 'html.parser')
        contentTable = soup.find('table',
                                 {"class": "centered bordered"
                                  })  # Use dictionary to pass key : value pair

        rows = contentTable.find_all('tr')
        lo = []
        i = 0

        for row in rows[1:]:
            lo.append("##")
            columns = row.find_all('td')
            for column in columns:
                if column.get_text() != "":
                    lo.append((column.get_text()).strip() + "@@")

            lo.append((columns[4].find('a')['href']).strip())
            i += 1
            if i == 1:
                break
        l1 = ""
        for r in lo:
            allContest = r.split("##")
            for eachContest in allContest:
                attrList = eachContest.split("@@")
                for attr in attrList:
                    l1 += attr + "\n"

        return l1

    # to return a list of n top contests
    elif len(codery_keywords_list) == 3:

        if codery_keywords_list[0] == "top" and codery_keywords_list[
                2] == "contests":
            n = int(codery_keywords_list[1])
        else:
            help_message
        URL = 'https://www.stopstalk.com/contests'
        content = requests.get(URL)
        soup = BeautifulSoup(content.text, 'html.parser')
        contentTable = soup.find('table',
                                 {"class": "centered bordered"
                                  })  # Use dictionary to pass key : value pair

        rows = contentTable.find_all('tr')
        lo = []
        i = 0

        for row in rows[1:]:
            lo.append("##")
            columns = row.find_all('td')
            for column in columns:
                if column.get_text() != "":
                    lo.append((column.get_text()).strip() + "@@")

            lo.append((columns[4].find('a')['href']).strip())
            i += 1
            if i == n:
                break
        l1 = ""
        for r in lo:
            allContest = r.split("##")
            for eachContest in allContest:
                attrList = eachContest.split("@@")
                for attr in attrList:
                    l1 += attr + "\n"

        return l1

    elif codery_keywords == '' or codery_keywords is None:
        return help_message
Exemple #3
0
def get_courses():
    return courses.get_courses(mysql)
Exemple #4
0
def index():
    courselist = courses.get_courses()
    return render_template("index.html", courses=courselist)