2.1.3. tasks.isis – ISIS-Related Tasks and Utilities

lib.tasks.isis.table_to_iter(table_string, process_header=<function <lambda> at 0x3c18ed8>, process_cell=<function <lambda> at 0x3dcd140>)

Takes a table on isis that is a list of items with fields designated by a single header, and converts them into a iterator of dicts, with keys based on the header, and values based on each row’s cells. For example, we can take a table like the schedule table:

section  type  course   credits  days   periods  building  room
0234     X     NOM2222  4        M W F  2        KITE      C101
                                 W      3        BUG       007
1230     X     DRA1234  3        M W F  1 2      DOG       G121
                                 R      1 2 3    MIL       G121
9999     X     ABC9876  5        TBA    TBA      JACK      TBA

and turn it into an iterator of dictionaries like:

[
    {"section":"0234", "type":"X", "course":"NOM2222", "credits":"4",
     "days":"M W F", "periods":"2", "building":"KITE", "room":"C101"},
    {"section":None, "type":None, "course":None, "credits":None,
     "days":"W", "periods":"3", "building":"BUG", "room":"007"},
    {"section":"1230", "type":"X", "course":"DRA1234", "credits":"3",
     "days":"M W F", "periods":"1 2", "building":"DOG", "room":"G121"},
    {"section":None, "type":None, "course":None, "credits":None,
     "days":"R", "periods":"1 2 3", "building":"MIL", "room":"G121"},
    {"section":"9999", "type":"X", "course":"ABC9876", "credits":"5",
     "days":"TBA", "periods":"TBA", "building":"JACK", "room":"TBA"}
]

The header is discarded.

Keyword arguments:

table_string
The inner contents of <table> tags.
process_header
A function that takes an argument of a header cell as an lxml HtmlElement, and outputs a result to be used as the header value. By default: pulls the text content as a string, strips leading and ending whitespace, and converts it to lowercase.
process_cell
A function that takes an argument of a header cell as an lxml HtmlElement, and outputs a result to be used as the cell value. By default: pulls the text content as a string, and strips leading and ending whitespace.
lib.tasks.isis.table_to_list(*args, **kwargs)

Does the same thing as table_to_iter(), but gives a list instead of an iterator.

Project Versions

Table Of Contents

Previous topic

2.1.2.1.4. ldap.utils – Processing for LDAP-Like Person Listings

Next topic

2.1.3.1.1. schedule_reader – Tools for Reading a Schedule from ISIS

This Page