pynami package¶
Subpackages¶
- pynami.schemas package
- Submodules
- pynami.schemas.activity module
- pynami.schemas.base module
- pynami.schemas.cogc module
- pynami.schemas.dashboard module
- pynami.schemas.default module
- pynami.schemas.grpadmin module
- pynami.schemas.history module
- pynami.schemas.mgl module
- pynami.schemas.search module
- pynami.schemas.training module
- pynami.schemas.tags module
- Submodules
Submodules¶
pynami.constants module¶
This module defines some constants needed for communication with the NaMi.
-
DEFAULT_PARAMS
= {'limit': 10000, 'page': 1, 'start': 0}¶ Default parameters to avoid pagination. The NaMi uses 5000 as limit when using the show all option.
Type: dict
-
class
URLMetaClass
[source]¶ Bases:
type
Meta class for
URLS
Makes the class accessible like a dict and prepends the base url when this is done. The relative URL string can be retrieved in the usual way as attributes.
-
class
URLS
[source]¶ Bases:
object
Contains all relative REST URLs.
The class attributes can be accessed like a dict in order to get the full URL (prepeding the
base URL
). The relative URL strings can be retrieved like normal class attributes.Example
>>> URLS.AUTH '/nami/auth/manual/sessionStartup' >>> URLS['AUTH'] 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup'
This is not just a dict so that each URL can be documented.
Note
Some URL strings have to formatted with some variables.
-
ALLE_TAETIGKEITEN
= '/nami/search-multi/all-visible-taetigkeiten'¶
-
AUSBILDUNG
= '/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/'¶
-
AUTH
= '/nami/auth/manual/sessionStartup'¶
-
BAUSTEIN
= '/module/baustein'¶
-
BEANTRAGUNG
= '/fz-beantragen/download-beantragung'¶
-
BEITRAGSART
= '/namiBeitrag/beitragsart/gruppierung/{grpId}/'¶
-
BEITRAGSART_MGL
= '/namiBeitrag/beitragsartmgl/gruppierung/{grpId}/'¶
-
EBENE
= '/orgadmin/ebene/'¶
-
EBENE1
= '/nami/search-multi/ebene/1'¶
-
EBENE2
= '/nami/search-multi/ebene/2/gruppierung1/{grpId}/'¶
-
EBENE3
= '/nami/search-multi/ebene/3/gruppierung2/{grpId}/'¶
-
FZ
= '/nami/fz/eigene-bescheinigungen/'¶
-
GESCHLECHT
= '/baseadmin/geschlecht/'¶
-
GETMGL
= '/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{gruppierung}/{mitglied}'¶
-
GET_TAG
= '/nami/mitglied-tagged-item/filtered-for-navigation/identitaet/identitaet/{mglId}/{tagId}'¶
-
GRPADMIN_GRPS
= '/nami/gruppierungen-for-grpadmin/parentgruppierung/node/root'¶
-
GRUPPIERUNGEN
= '/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root'¶
-
HISTORY
= '/dashboard/history-entries/flist'¶
-
INVOICE
= '/nami/rechin-for-grpadmin/rechin/gruppierung/'¶
-
INVOICE_PDF
= '/nami/rechin-for-grpadmin/pdf'¶
-
KONFESSION
= '/baseadmin/konfession/'¶
-
LAND
= '/baseadmin/land/'¶
-
LOGOUT
= '/nami/auth/logout'¶
-
MGLTYPE
= '/nami/enum/mgltype'¶
-
MGL_HISTORY
= '/nami/mitglied-history/filtered-for-navigation/mitglied/mitglied/'¶
-
MGL_HISTORY_EXT
= '/nami/mitglied-history-with-values/filtered-for-navigation/mitglied/mitglied/'¶
-
MGL_TAETIGKEITEN
= '/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'¶
-
NOTIFICATIONS
= '/dashboard/notification-entries/flist'¶
-
REGION
= '/baseadmin/region/'¶
-
SEARCH
= '/nami/search-multi/result-list'¶
-
SEARCH_ALL
= '/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{gruppierung}/flist'¶
-
SERVER
= ''¶
-
STAAT
= '/baseadmin/staatsangehoerigkeit/'¶
-
STATS
= '/dashboard/stats/stats'¶
-
STATUS_LIST
= '/nami/search-multi/status-list'¶
-
STUFENWECHSEL
= '/mgl-verwaltungS/stufenwechsel'¶
-
TAGLIST
= '//tagging/getTagList'¶
-
TAGS
= '/nami/mitglied-tagged-item/filtered-for-navigation/identitaet/identitaet/{mglId}/flist'¶
-
TK_AUF_GRP
= '//nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{grpId}/'¶
-
TK_CAEA_GRP
= '//nami/caea-group/filtered-for-navigation/taetigkeit/taetigkeit/{taetigkeitId}/'¶
-
TK_GRP
= '//nami/gf/gruppierung'¶
-
TK_UG
= '//nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/{taetigkeitId}/'¶
-
UNTERGLIEDERUNG
= '/orgadmin/untergliederung'¶
-
ZAHLUNGSKONDITION
= '/baseadmin/zahlungskondition/'¶
-
pynami.nami module¶
NAMI library in python
This module contains the main class NaMi
and a few simple exception
definitions.
-
class
NaMi
(config={}, **kwargs)[source]¶ Bases:
object
Main class for communication with the DPSG NaMi
Example
from pynami.nami import NaMi from pynami.tools import tabulate2x with NaMi(username='MITGLIEDSNUMMER', password='PASSWORD') as nami: print(tabulate2x(nami.search()))
Parameters: config ( dict
, optional) – Authorization configuration-
_check_response
(response)[source]¶ Check a requests response object if the NaMi response looks ok. This currently checks some very basic things.
Raises: NamiHTTPError
– When HTTP communication failesNamiResponseSuccessError
– When the NaMi returns an error
-
_get_baseadmin
(key, grpId=None, mglId=None, taetigkeitId=None, **kwargs)[source]¶ Base function for retrieving all core lists from the NaMi
Parameters: - key (
str
) – Name of the wanted items - grpId (
int
orstr
, optional) – Group id - mglId (
int
orstr
, optional) – Member id (not the DPSG Mitgliedsnummer) - taetigkeitId (
int
, optional) – Id of an activity. A list of all possible ids can be found in the section Activity types. This is only required for the URLs which needs to be formatted with this value.
Keyword Arguments: Returns: The returned default values
Return type: - key (
-
auth
(username=None, password=None)[source]¶ Authenticate against the NaMi API. This stores the jsessionId cookie in the requests session. Therefore this needs to be called only once.
This also stores your id (not the Mitgliednummer) for later pruposes.
Parameters: Returns: The requests session, including the auth cookie
Return type:
-
beitragsarten
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: Each possible fee type
Return type:
-
beitragsarten_mgl
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: Each possible fee for a member
Return type:
-
bescheinigungen
(**kwargs)[source]¶ Get all certificates of inspection
Returns: A list of all your certificates of inspection Return type: list
ofSearchBescheinigung
-
countries
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: List of all possible countries with their names and ids
Return type:
-
download_beantragung
(**kwargs)[source]¶ Open the application form for a certificate of good conduct as a PDF file.
Parameters: **kwargs – See open_download_pdf()
.
-
download_bescheinigung
(id_, **kwargs)[source]¶ Open a certificate as a PDF file
Parameters: - id (int) – Internal id of the certificate
- **kwargs – See
open_download_pdf()
.
-
download_invoice
(id_, **kwargs)[source]¶ Downloads and opens an invoice as a pdf document.
Parameters: - id (int) – Id of the invoice (not the regular invoice number)
- **kwargs – See
open_download_pdf()
.
-
ebene2
(ebene1)[source]¶ You can choose a Bezirk which you belong to.
Parameters: ebene1 (int) – Group id of a Diözese Returns: List of possible Bezirken you are associated with Return type: list
ofBaseadmin
-
ebene3
(ebene2)[source]¶ You can choose a Stamm which you belong to.
Parameters: ebene2 (int) – Group id of a Bezirk Returns: List of possible Stämmen you are associated with Return type: list
ofBaseadmin
-
geschlechter
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: You can choose between three genders: male, female and diverse.
Return type:
-
get_activity
(mgl, id_)[source]¶ Get an activity by its id.
Parameters: - mgl (int) – Member id (not DPSG Mitgliedsnummer)
- id (int) – Id of the activity. This will probably originate from an
activity search result, e.g. by calling
mgl_activities()
.
Returns: The Activity object containing all details.
Return type:
-
get_ausbildung
(mglId, id_)[source]¶ Get a training by its id.
Parameters: - mglId (int) – Member id (not DPSG Mitgliedsnummer)
- id (int) – Id of the training. This will probably originate from an
training search result, e.g. by calling
mgl_ausbildungen()
.
Returns: The Ausbildung object containing all details about the training.
Return type:
-
get_bescheinigung
(id_)[source]¶ View a certificate of inspection by its id
Parameters: id (int) – The internal id of the certificate Returns: An object holding all important details about the inspection Return type: Bescheinigung
-
get_mgl_history
(mglId, id_, ext=True)[source]¶ Get a member history entry by its id.
Parameters: - mglId (int) – Member id (not DPSG Mitgliedsnummer)
- id (int) – Id of the entry. May originate from a search result,
e.g. by calling
mgl_history()
. - ext (
bool
, optional) – If the extended history format should be used. Defaults toTrue
.
Returns: The object containing all vital information about this history entry.
Return type:
-
get_tag
(mglId, tagId)[source]¶ Get a tag by its id
Parameters: Returns: The tag object with all important details
Return type:
-
grpId
¶ Group id of the user
Returns: int
-
grpadmin_grps
¶ Choose from a list of groups that you are associated with for group admin
Type: list
ofBaseadmin
-
gruppierungen
¶ Choose from a list of groups that you are associated with for member admin
Type: list
ofBaseadmin
-
history
(**kwargs)[source]¶ Dashboard function
Returns: Last editing events like updating and creating members.In the NaMi these are displayed in the dashboard. Return type: list
ofHistoryEntry
-
invoice
(groupId, invId)[source]¶ Get an invoice by its id.
Parameters: - groupId (int) – Group id
- invId (int) – Id of the invoice. This will probably originate from
a search result, e.g. by calling
invoices()
.
Returns: The Invoice object containing all details.
Return type:
-
invoices
(groupId=None, **kwargs)[source]¶ List of all invoices of a group
Parameters: groupId ( int
, optional) – Group idReturns: All invoices of the specified group Return type: list
ofSearchInvoice
-
konfessionen
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: All denominations
Return type:
-
logout
()[source]¶ This should be called at the end of the communication. It is called when exiting through the
__exit__()
method.
-
mgl_activities
(mgl)[source]¶ List of all activities of a member
Parameters: mgl (int) – Member id (not DPSG Mitgliedsnummer) Returns: All activities of the member (even those which have already ended) Return type: list
ofActivity
-
mgl_ausbildungen
(mglId)[source]¶ Get all trainings from a Mitglied.
Parameters: mglId (int) – Member id (not DPSG Mitgliedsnummer) Returns: All trainings of the member Return type: list
ofSearchAusbildung
-
mgl_history
(mglId, ext=True)[source]¶ Get all history changes from a Mitglied.
Parameters: Returns: All history entries of the member
Return type: list
ofHistoryEntry
-
mgltypes
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: You can have one of three different member types
Return type:
-
mitglied
(mglId=None, method='GET', grpId=None, **kwargs)[source]¶ Gets or updates a Mitglied.
The keyword arguments are passed on to the HTTP communication
Parameters: - mglId (
int
, optional) – ID of the Mitglied. This is not the DPSG Mitgliedsnummer. Defaults to the user. - method (
str
) – HTTP Method. Should be'GET'
or'PUT'
, defaults to'GET'
. - grpId (
int
, optional) – The DPSG Stammesnummer, e.g.131913
. The default (None
) takes the value from the internal attribute__config
.
Returns: The retrieved or respectively updated Mitglied. Note that the
austrittsDatum
attribute is not part of the returned data set.Return type: - mglId (
-
myId
¶ NaMi internal id of the user
Returns: int
-
notifications
(sortproperty=None, sortdirection='ASC', **kwargs)[source]¶ Dashboard function
Returns: All current notifications (like tier changes of members). In the NaMi these are displayed in the dashboard. Return type: list
ofNotification
-
regionen
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: All possible Bundeslaender
Return type:
-
search
(**kwargs)[source]¶ Run a search for members
Todo
- Check search terms and formatting. Also some search keys can only be used mutually exclusive.
Parameters: **kwargs – Search keys and words. Be advised that some search words must have a certain formatting or can only take a limited amount of values. Returns: The search results Return type: list
ofSearchMitglied
See also
SearchSchema
for a complete list of search keys
-
search_all
(grpId=None, filterString=None, searchString='', sortproperty=None, sortdirection='ASC', **kwargs)[source]¶ Search function for filtering the whole member list with limited filter options.
It is also possible to sort the results.
Parameters: - filterString (
str
, optional) – Filter attribute. - searchString (
str
, optional) – You can search within the chosen filter attribute. The Format must match the type of the filter attribute. - sortproperty (
str
, optional) – Attribute by wich the results shall be sorted. - sortdirection (
str
, optional) – Direction of sorting. Can take the valuesASC
(wich is the default) andDESC
.
Returns: The search results
Return type: - filterString (
-
staaten
(grpId=None, mglId=None)[source]¶ Get default values
Parameters: Returns: A quite long list of different nationalities
Return type:
-
stats
¶ Contains counts from different tiers. The actual list of
StatCategory
is in thestatsCategories
attribute.Type: Stats
-
subdivision
¶ Which division you are associated with. This one is only used for searching.
Type: list
ofBaseadmin
-
tagList
¶ A different list of fee types but with basically the same content. This one is used for searching members.
Deprecated since version 0.3.3: Only returns an empty list and has therefore become useless.
Type: list
ofBaseadmin
Get all tags of a member
Parameters: mglId (int) – Member id (not DPSG Mitgliedsnummer) Returns: List of the search results Return type: list
ofSearchTag
-
tk_auf_grp
(grpId, mglId, **kwargs)[source]¶ Get all possible activities for a certain group
Parameters: Returns: List of possible activities
Return type:
-
tk_caea_grp
(grpId, mglId, taetigkeitId, **kwargs)[source]¶ Get all possible access rights for an activity
Parameters: Returns: List of possible access rights
Return type:
-
tk_grp
(grpId, mglId, **kwargs)[source]¶ Get all possible groups for an activity
Parameters: Returns: List of possible groups
Return type:
-
tk_ug
(grpId, mglId, taetigkeitId, **kwargs)[source]¶ Get all possible subdivision for an activity
Parameters: Returns: List of possible subdivision
Return type:
-
update_activity
(mgl, act)[source]¶ Update an activity
Parameters: Returns: A new updated object
Return type: Warning
This has not been tested yet!
-
update_ausbildung
(mglId, ausbildung)[source]¶ Update a training
Parameters: - mgl (int) – Member id (not DPSG Mitgliedsnummer)
- ausbildung (
Ausbildung
) – Updated data set. The training id is taken form this data set.
Returns: A new updated object
Return type: Warning
This has not been tested yet!
-
-
exception
NamiHTTPError
[source]¶ Bases:
Exception
Raised when the HTTP status code was not as expected!
pynami.util module¶
Some utility functions that are used by other classes and methods from this # package but not directly connected to the NaMi.
-
class
ExtractHrefParser
(*, convert_charrefs=True)[source]¶ Bases:
html.parser.HTMLParser
HTML parser for extracting a URL
-
extract_url
(htmlstr)[source]¶ Extract a URL from a HTML string.
Parameters: htmlstr (str) – The HTML string which will be parsed. Returns: The URL Return type: str
-
open_download_pdf
(content, open_file=True, save_file=False, timeout=10, filename='')[source]¶ Open and/or save a downloaded PDF file.
When you only want to open the file: To avoid having to deal with graphical save-the-file dialogues a temporary file inside a temporary directory is created which is deleted after a timeout that is used to open the file. During this timeout the program is blocked.
Parameters: - content (bytes) – Content of the downloaded file
- open_file (
bool
, optional) – Wether to directly open the downloaded file. Defaults toTrue
. - save_file (
bool
, optional) – Wether to save the downloaded file to disc. Defaults toFalse
. - timeout (
float
, optional) – Time the system has for opening the file. Defaults to 10 seconds. - filename (
str
, optional) – Full path to save file
pynami.tools module¶
Some utility functions for user convenience
-
export_xlsx
(data, attrs=None, includeheader=True, tableName='Tabelle1', sheetName='Data', write_to_file=False, filepath='')[source]¶ Create a Microsoft Excel Wokbook from a given dataset. The data can optionally be saved to a file.
Parameters: - data (list) – Data objects. They should all belong to the same class.
- attrs (
list
of str, optional) – Attribute names for the CSV table. If left empty (None
) the value of the first_tabkeys
attribute in the list is taken. - includeheader (
bool
, optional) – Whether to include headers in the output. Defaults toTrue
. - tableName (
str
, optional) – Name of the table. Defaults to ‘Tabelle1’. - sheetName (
str
, optional) – Name of the worksheet. Defaults to ‘Data’. - write_to_file (
bool
, optional) – If the workbook should be saved to a file. Defaults toFalse
. - filepath (
str
, optional) – Full path to the Excel file where the data should be saved. If left empty the default savefile dialog will be invoked via the moduletkinter
.
Returns: The created workbook.
Return type:
-
make_csv
(data, attrs=None, includeheader=True, delimiter=', ')[source]¶ Makes a CSV formatted string from a data set
Parameters: - data (list) – Data objects. They should all belong to the same class.
- attrs (
list
of str, optional) – Attribute names for the CSV table. If left empty (None
) the value of the first_tabkeys
attribute in the list is taken. - includeheader (
bool
, optional) – Whether to include headers in the output. Defaults toTrue
.
Returns: CSV formatted data
Return type:
-
send_emails
(mitglieder, to='', method='bcc', email1=True, email2=True, open_browser=True)[source]¶ Send emails to several members.
Parameters: - mitglieder (list) – The List contents can be either
SearchMitglied
orMitglied
- to (
str
, optional) – Primary recipient - method (
str
, optional) – If you want to send your mails as bcc or something else. Currently only bcc is supported. - email1 (
bool
, optional) – If emails should be send to the primary address of the members. - email2 (
bool
, optional) – If emails should be send to the email account of the member’s parent. - open_browser (
bool
, optional) – IfTrue
the link is opened directly by the system. On a computer this may open your default mail program.
Returns: The mailto link
Return type: - mitglieder (list) – The List contents can be either