Ejemplo n.º 1
0
def ensure_session():
    if 'session' not in globals():
        global EMAIL
        global PASSWORD
        global session
        try:
            session = use_json()
        except Exception:
            EMAIL = os.environ['librus_email']
            PASSWORD = os.environ['librus_password']
            session = create_session(
                EMAIL,
                PASSWORD,
                cache=cache.AlchemyCache(engine_uri='sqlite:///:memory:'))
            session.user.dump_credentials()
Ejemplo n.º 2
0
def count_averages():
    logging.info('Recived json %s', request.json)
    try:
        session = create_session(request.json['email'],
                                 request.json['password'],
                                 cache=my_cache)
        logging.info('Session created %s', session)
    except exceptions.LibrusPortalInvalidPasswordError:
        logging.info('Bad password')
        return render_template('bad_password.html')
    except exceptions.CaptchaRequired:
        logging.info('Captcha')
        return render_template('damn_captcha.html')
    return render_template('averages.html',
                           averages=subjects_averages(
                               session.grades_categorized),
                           percentages=percentage_average(session.grades()))
Ejemplo n.º 3
0
def count_user_attendances():
    logging.info('Recived json %s', request.json)
    try:
        session = create_session(request.json['email'],
                                 request.json['password'],
                                 cache=my_cache)
        logging.info('Session created %s', session)
    except exceptions.LibrusPortalInvalidPasswordError:
        logging.info('Bad password')
        return render_template('bad_password.html')
    except exceptions.CaptchaRequired:
        logging.info('Captcha')
        return render_template('damn_captcha.html')
    return render_template(
        'attenances.html',
        attendances=count_attendances(session.attendances()),
        percentages=percentages_of_attendances(session.attendances()),
        present=present_percentage(session.attendances()),
        absences=session.all_absences)
Ejemplo n.º 4
0
import os
import sys

sys.path.extend(['./'])

email = os.environ['librus_email']
password = os.environ['librus_password']

from librus_tricks import exceptions, create_session, cache

session = create_session(email, password, cache=cache.AlchemyCache(engine_uri='sqlite:///:memory:'))


def test_auth():
    return session.user.is_revalidation_required(use_query=True)


def test_attendance():
    return session.attendances()


def test_exams():
    return session.exams()


def test_grades():
    return session.grades()


def test_timetable():
    return session.tomorrow_timetable, session.today_timetable, session.timetable()
Ejemplo n.º 5
0
import requests
from hashlib import sha1

from flask import request
from pymessenger.bot import Bot

from librus_tricks import create_session

from librekbot import app, db
from librekbot.models import Recipient, SentAnnouncement

bot = Bot(config.access_token)

# When Librus and Synergia accounts have diffrent passwords
# session = SynergiaClient(authorizer('MAIL', 'HASLOLIBRUS')[0], synergia_user_passwd='HASLOSYNERGIA')
session = create_session(config.login, config.password)


# We will receive messages that Facebook sends our bot at this endpoint
@app.route("/", methods=['GET', 'POST'])
def receive_message():
    if request.method == 'GET':
        """Before allowing people to message your bot, Facebook has implemented a verify token
        that confirms all requests that your bot receives came from Facebook."""
        token_sent = request.args.get("hub.verify_token")
        return verify_fb_token(token_sent)
    # if the request was not get, it must be POST and we can just proceed with sending a message back to user
    else:
        # get whatever message a user sent the bot
        output = request.get_json()
        # if(not session.user.is_valid):
Ejemplo n.º 6
0
# Create session (with support for messages, require the same password for Portal Librus and Synergia)
from librus_tricks import create_session
import librus_tricks
import info

from datetime import datetime

session = create_session(info.settings[0], info.settings[1])


def GetLessons(day: int = 0):
    lessons = {}
    table = session.tomorrow_timetable.lessons if day == 1 else session.today_timetable.lessons
    for lesson in table:
        try:
            lessons[
                f'{lesson.start.strftime("%H:%M")}-{lesson.end.strftime("%H:%M")}'] = str(
                    lesson.subject)
        except IndexError:
            pass

    return lessons


def GetGradesByTeacher(teacher):
    grades = {}
    for grade in filter(
            lambda g: str(teacher).lower() in str(g.teacher).lower(),
            session.grades()):
        try:
            grades[grade.grade] = grade.comments[0]