sigaa.api.API Documentation

class sigaa.api.API(domain='sigaa.ufpi.br')

Class to instantiate the API object.

Parameters:domain (String) – The platform domain of the university server.
Attr session:Holds a requests.Session() object.
>>> from sigaa.api import API
>>> api = API("sigaa.ufma.br") # already executes API.generate_session(domain)
authenticate(username, passwd)

Method to authenticate the sigaacli.API.session.

Parameters:
  • username (String) – The username of the student.
  • passwd (String) – The password of the student.
Returns:

True for success or False for failure.

Return type:

Boolean

>>> from sigaa.api import API
>>> api = API("sigaa.ufpi.br")
>>> api.authenticate("username", "password")
False or True
deauthenticate()

Method to execute the logOff operation on SIGAA platform. It will return True is the operation was executed with success.

Returns:True if the session was deauthenticated with success or False if it fails.
Return type:Boolean
>>> from sigaa.api import API
>>> api = API('sigaa.ufma.br')
>>> api.authenticate('macielti', 'PaSsWoRd')
False
>>> api.deauthenticate()
True
get_all_users()

Method to scrap the fullname and username of all the users of the platform.

Warning

This process can be a little slow, like up to 20 minutes, but this can be fast like 2 minutes. This will depends on a number of factors like the total number of students, the load of the server, your internet connection.

You can use Python Generators to iterate more efficientely combined with Threads, just convert the returned list to a generator.

Example of how to convert a list in to a generator:

>>> from sigaa.api import API
>>> api = API()
>>> api.authenticate('macielti', 'Si6Dqr1biY1a')
>>> users = api.get_all_users()
>>> ( user for user in users )
<generator object <genexpr> at 0x7f366e97a678>
Returns:List of users infos.
Return type:list. Example: [‘BRUNO DO NASCIMENTO MACIEL (macielti)’, ..]
get_domain()

Method that returns the setted domain.

get_session()

Method that returns a requests.Session() object.

is_authenticated()

Method that returns the if the session is authenticated or not.

Returns:True if you are authenticated or False if not.
Return type:Boolean
>>> from sigaa.api import API
>>> api = API('sigaa.ufma.br')
>>> api.is_authenticated()
False
search_user(query)

Search for a username or fullname of a user, it returns a list of users info match. It will search only from the start to th end of the query, it won’t search from the middle of the users fullname or username.

Parameters:query (String) – Beginning of a username or fullname.
Returns:List of users infos.
Return type:list. Example: [‘BRUNO DO NASCIMENTO MACIEL (macielti)’, ..]
send_message(users, subject, message)

Send message to a list of users.

Parameters:
  • users (list) – A list of users. Example: [“BRUNO DO NASCIMENTO MACIEL (macielti)”, …]
  • subject (String) – Subject of the message.
  • message (String) – Message text.
Returns:

True for success or False for failure.

Return type:

Boolean

>>> from sigaa.api import API
>>> api = API()
>>> api.authenticate('macielti', '1aT6SwWMgWvP')
True
>>> api.send_message(["BRUNO DO NASCIMENTO MACIEL (macielti)"], "Subject", "Message Text")
True