module automation_students.projects_repository

Inheritance diagram of ensae_teaching_cs.automation_students.projects_repository

Short summary

module ensae_teaching_cs.automation_students.projects_repository

Some automation helpers to grab mails from students about their projects.

source on GitHub

Classes

class truncated documentation
ProjectsRepository Handle a repository of students projects. See example sphx_glr_gyexamples_automation_fetch_student_projects_from_gmail.py. …

Properties

property truncated documentation
Groups returns all available groups in the repository
Location  

Static Methods

staticmethod truncated documentation
create_folders_from_dataframe creates a series of folders for groups of students
get_regex retrieve data from file suivi.rst using a regular expression
match_mail tries to match a name among a list of mails
match_mails tries to match a series of names among a list of mails

Methods

method truncated documentation
__init__ location of the repository
convert_files convert all notebooks and python scripts into html for a group
dump_group_mails enumerates all mails sent by or sent to a given group
enumerate_group_files enumerate all files in a group
enumerate_group_mails enumerates all mails sent by or sent to a given group
get_emails retrieve student emails from file suivi.rst
get_group_location return the local folder associated to a group
get_sections extract sections from a filename used to follow a group of students
get_videos retrieve student emails from file suivi.rst
list_mails return the number of mails of a group
remove_group remove a group
unzip_convert unzip files and convert notebooks into html
unzip_files unzip files and convert notebooks into html
write_summary produces a summary and uses a Jinja2 template
zip_group zip a group

Documentation

Some automation helpers to grab mails from students about their projects.

source on GitHub

class ensae_teaching_cs.automation_students.projects_repository.ProjectsRepository(location, suivi='suivi.rst', fLOG=<function noLOG>)[source]

Bases : object

Handle a repository of students projects. See example sphx_glr_gyexamples_automation_fetch_student_projects_from_gmail.py.

source on GitHub

location of the repository

Paramètres:
  • location – location of the repository
  • suivi – name of the file gathering information about each project

source on GitHub

Groups

returns all available groups in the repository

source on GitHub

Location

return – location of the repository

source on GitHub

exception MailNotFound[source]

Bases : Exception

raises an exception if mail not found

source on GitHub

__init__(location, suivi='suivi.rst', fLOG=<function noLOG>)[source]

location of the repository

Paramètres:
  • location – location of the repository
  • suivi – name of the file gathering information about each project

source on GitHub

_email_regex = re.compile('[*] *e?mails? *: *([^*+\\n]+)')
_gitlab_regex = re.compile('[*] *gitlab *: *([^*+\\n]+[.]git)')
_known_strings = ['xavierdupre.fr', 'doodle', 'ensaenotebook', 'teralab', 'outlook.com', 'gohlke', 'support.google', 'help.github', 'api.jcdecaux']
_regex_split = re.compile('[-;,. @]')
_video_regex = re.compile('[*] *videos? *: *([^*\\n]+)')
convert_files(group)[source]

convert all notebooks and python scripts into html for a group

Paramètres:group – group name
Retourne:list of new files

source on GitHub

static create_folders_from_dataframe(df, root, report='suivi.rst', col_student='Eleves', col_group='Groupe', col_subject='Sujet', col_mail=None, overwrite=False, email_function=None, must_have_email=True, skip_if_nomail=False, skip_names=None, fLOG=<function noLOG>)[source]

creates a series of folders for groups of students

Paramètres:
  • root – where to create the folders
  • col_student – column which contains the student name (firt name + last name)
  • col_group – index of the group (it can be None if each student is a group)
  • col_subject – column which contains the subject
  • col_mail – if there is a column which contains the mail in the input dataframe
  • df – DataFrame
  • email_function – function which infers email from first and last names, see below
  • report – report file
  • overwrite – if False, skip if the report already exists
  • must_have_email – if True, raises an exception if no mail is found
  • skip_if_nomail – skip a name if no mail is found
  • skip_names – less checking for a given set of names
Retourne:

list of creates folders

The function email_function has the following signature:

def email_function(names):
    # part of a names is a list of tokens
    # ...
    return list of mails, skip=boolean

The boolean tells the function to skip this group. email_function can be a list of mails. In that case, this function is replaced by match_mails.

source on GitHub

dump_group_mails(renderer, group, mailbox, subfolder, date=None, skip_function=None, max_dest=5, filename='index_mails.html', overwrite=False, skip_if_empty=False, convert_files=False)[source]

enumerates all mails sent by or sent to a given group

Paramètres:
  • renderer – instance of class EmailMessageListRenderer
  • group – group
  • mailbox – mailbox (see pymmails)
  • subfolder – which subfolder of the mailbox to look into
  • date – date
  • skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)
  • max_dest – maximum number of receivers
  • filename – filename which gathers a link to every mail
  • overwrite – overwrite
  • skip_if_empty – skip if no mail?
  • convert_files – unzip and convert
Retourne:

list of files (see EmailMessageListRenderer.write)

zip, gz, rar, 7z can be uncompressed. It then convert .py and .ipynb into html.

source on GitHub

enumerate_group_files(group)[source]

enumerate all files in a group

Paramètres:group – group
Retourne:iterator on files

source on GitHub

enumerate_group_mails(group, mailbox, subfolder, date=None, skip_function=None, max_dest=5)[source]

enumerates all mails sent by or sent to a given group

Paramètres:
  • group – group (if None, goes through all mails)
  • mailbox

    mailbox (see pymmails)

  • subfolder – which subfolder of the mailbox to look into
  • date – date
  • skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)
  • max_dest – maximum number of receivers
Retourne:

iterator on mails

source on GitHub

get_emails(group, skip_if_empty=False)[source]

retrieve student emails from file suivi.rst

Paramètres:
  • group – group
  • skip_if_empty – skip if no mail?
Retourne:

list of mails

source on GitHub

get_group_location(group)[source]

return the local folder associated to a group

Paramètres:group – group name
Retourne:local folder

source on GitHub

static get_regex(path, regex, suivi='suivi.rst', skip_if_empty=False)[source]

retrieve data from file suivi.rst using a regular expression

Paramètres:
  • path – sub folder to look into
  • suivi – name of the file suivi.rst
  • skip_if_empty – skip of no mail?
Retourne:

list of mails

source on GitHub

get_sections(group)[source]

extract sections from a filename used to follow a group of students

Paramètres:group – group
Retourne:dictionary { section : content }

Example of a file:

rapport
+++++++

* bla 1

extrait
+++++++

::

    paragraphe 1

    paragraphe 2

source on GitHub

get_videos(group)[source]

retrieve student emails from file suivi.rst

Paramètres:group – group
Retourne:list of videos

source on GitHub

list_mails(group)[source]

return the number of mails of a group

Paramètres:group – group name
Retourne:list of mails

source on GitHub

static match_mail(name, emails, threshold=3, exc=True)[source]

tries to match a name among a list of mails

Paramètres:
  • name – a name (first name last name separated by a space)
  • emails – list of emails
  • threshold – above this threshold, mails and names don’t match
  • exc – raise an Exception if not found
Retourne:

list of available mails, boolean

The second results is True if no email were found in the list.

source on GitHub

static match_mails(names, emails, threshold=3, exc=True, skip_names=None)[source]

tries to match a series of names among a list of mails

Paramètres:
  • names – list of names (first name last name separated by a space)
  • emails – list of emails
  • threshold – above this threshold, mails and names don’t match
  • exc – raise an Exception if not found
  • skip_names – the second boolean is True is one of the name belongs to this list
Retourne:

list of available mails, boolean

The second results is True if no email were found in the list.

source on GitHub

remove_group(group)[source]

remove a group

Paramètres:group – group
Retourne:list of removed files

see remove_folder

source on GitHub

unzip_convert(group)[source]

unzip files and convert notebooks into html

Paramètres:group – group name
Retourne:list of new files

source on GitHub

unzip_files(group)[source]

unzip files and convert notebooks into html

Paramètres:group – group name
Retourne:list of new filess

source on GitHub

write_summary(render=None, link='index_mails.html', outfile='index.html', title='summary', nolink_if=None)[source]

produces a summary and uses a Jinja2 template

Paramètres:
  • render – instance of EmailMessageRenderer), can be None
  • link – look for this file in each folder
  • outfile – output file
  • nolink_if – link containing those strings will be removed (if None, a default set will be assigned)
Retourne:

summary

the current default template is:

<?xml version="1.0" encoding="utf-8"?>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<html>
<head>
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="{{ css }}">
</head>
<body>
<h1>{{ title }}</h1>
<ol type="1">
{% for ps in groups %}
    <li><a href="{{ ps["link"] }}">{{ ps["group"] }}</a><small><i>
        {{ ps["nb"] }} files - {{ format_size(ps["size"]) }} -
        last mail {{ ps["emails"][-1]["date"] }} ---
        {{ len(ps["attachments"]) }} attachments</i></small>
    {% if len(ps["attachments"]) > 0 %}
        <ul>
        {% for day, att, data in ps["attachments"] %}
            <li>att: {{ day }} - <a href="{{ att }}">{{ os.path.split(att)[-1] }}</a></li>
        {% endfor %}
        {% for date, from_, url, domain, last in ps["links"] %}
            <li>link: {{ date }} <a href="{{ url }}">{{ domain }} // {{ last }}</a> from {{ from_ }}</li>
        {% endfor %}
        </ul>
    {% endif %}
    {% if len(ps["created_files"]) > 0 %}
        <ul>
        {% for name, relpath, size in ps["created_files"] %}
            <li>added: <a href="{{ relpath }}">{{ name }}</a> {{ size }}</li>
        {% endfor %}
        </ul>
    {% endif %}
    </li>
{% endfor %}
</ol>
</body>
</html>

source on GitHub

zip_group(group, outfile, addition=None)[source]

zip a group

Paramètres:
  • group – group
  • outfile – output file
  • addition – additional files (sequence)
Retourne:

list of zipped files

source on GitHub