librus apix
v1.1.0
pip install librus-apix
Importante
É aconselhável executar todos os testes antes de tentar tudo. Algumas escolas têm configurações de librus diferentes que podem causar erros/avisos. Se você encontrar algum, abra um problema ou contribua com um PR
pip install pytest
pytest --token {output of token.API_Key}
Para fins de desenvolvimento, criei um servidor HTML simulado simples
# generate all html pages and run server
python scripts/generate_all.py
python server.py
# now unless you've changed the server.py default port you should be good to go and run
pytest
# if you did change the port, you have to edit the tests/conftest.py file accordingly
from librus_apix . client import Client , Token , new_client
# create a new client with empty Token()
client : Client = new_client ()
# update the token
_token : Token = client . get_token ( "username" , "password" )
# now you can pass your client to librus-apix functions
from librus_apix . client import Token , Client , new_client
key = client . token . API_Key
# you can store this key and later load it in ways like this:
## Load directly into token object
token = Token ( API_Key = token_key )
client : Client = new_client ( token = token )
## or put it into existing client
client . token = token
## or into empty token
client . token . API_Key = key
from librus_apix . grades import get_grades
grades , average_grades , descriptive_grades = get_grades ( client )
for semester in grades :
for mark in semester [ "Mathematics" ]:
print ( mark . grade )
for semester in descriptive_grades :
for mark in semester [ "Emotional development" ]:
print ( mark . grade )
from librus_apix . announcements import get_announcements
announcements = get_announcements ( client )
for a in announcements :
print ( a . description )
from librus_apix . attendance import get_attendance
first_semester , second_semester = get_attendance ( client )
for attendance in first_semester :
print ( attendance . symbol , attendance . date )
from librus_apix . attendance import get_attendance_frequency
first , second , overall = get_attendance_frequency ( client )
print ( f" { first * 100 } %" )
from librus_apix . homework import get_homework , homework_detail
# date from-to up to 1 month
date_from = '2023-03-02'
date_to = '2023-03-30'
homework = get_homework ( client , date_from , date_to )
for h in homework :
print ( h . lesson , h . completion_date )
href = h . href
details = homework_detail ( client , href )
print ( details )
from librus_apix . messages import recipient_groups , get_recipients , send_message
groups = recipient_groups ( client )
recipients = get_recipients ( client , groups [ 0 ])
my_recipient = recipients [ "John Brown" ]
my_second_recipient = recipients [ "Barbara Brown" ]
sent = send_message ( client ,
"Message Title" ,
"Message n content" ,
[ my_recipient , my_second_recipient ]
)
if sent == True :
print ( "Sent!" )
else :
print ( "Error sending a message!" )
from librus_apix . messages import get_received , message_content
messages = get_received ( client , page = 1 )
for message in messages :
print ( message . title )
href = message . href
print ( message_content ( client , href ))
from librus_apix . schedule import get_schedule , schedule_detail
month = '2'
year = '2023'
schedule = get_schedule ( client , month , year )
for day in schedule :
for event in schedule [ day ]:
print ( event . title )
prefix , href = event . href . split ( '/' )
details = schedule_detail ( client , prefix , href )
print ( details )
from datetime import datetime
from librus_apix . timetable import get_timetable
monday_date = '2023-04-3'
monday_datetime = datetime . strptime ( monday_date , '%Y-%m-%d' )
timetable = get_timetable ( client , monday_datetime )
for weekday in timetable :
for period in timetable [ weekday ]:
print ( period . subject , period . teacher_and_classroom )
# initial should be always called with a new token
initial_notifications, new_ids = get_initial_notification_data(client)
sleep(150)
# after that you retrieve the new Notifications with new_ids filtered out
new_notifications, new_ids = get_new_notification_data(client, new_ids)
# see more in docs
from librus_apix . student_information import student_information
info = student_information ( client )
print ( info . lucky_number )
# Proxy can be added with
client = new_client ( proxy = { "https" : "http://my-proxy.xyz" })
# or
client . proxy = { "https" : "http://my-proxy.xyz" }
git clone https://github.com/RustySnek/librus-apix
cd librus-apix
python -m venv venv
source ./venv/bin/activate
pip install requirements.txt
# Installing library with editable flag
pip install -e .