Member class¶
- class Member(member_db_path, db_key, table_name='members')¶
Bases:
MojoSkelSubclass of MojoSkel providing member-specific database functions
This class connects to a SQLite database and supports importing member data from CSV and performing queries like lookup by name or member number
- Parameters:
(Path) (member_db_path) – Path to the SQLite database file
db_key (
str) – key to unlock the encrypted sqlite database, unencrypted if sqlcipher3 not installed or unset(str) (table_name) – (optional) Table name to use. Defaults to “members”
- count()¶
- Return type:
int- Returns:
count of the number of rows in the table, or 0 if no table
- download_csv(session, url, merge=False)¶
Download the CSV from url and import into the sqlite database If a previous table exists, generate a diff
- Parameters:
session (
Session) – Requests session to use for downloadurl (
str) – url of the csv to downloadmerge (
bool) – (optional) If True, merge into existing table. Defaults to False.
- get_bool(entry_name, member_number)¶
Return a bool for a member entry that is a tick box on membermojo
- Parameters:
entry_name (
str) – The entry name to return as a boolmember_number (
int) – The member number to check value of entry_name
- Return type:
bool- Returns:
True is entry is yes otherwise False
- Raises:
ValueError – If entry name not found
- get_first_last_name(member_number)¶
Get full name for a given member number
- Parameters:
member_number (
int) – Member number to look up- Return type:
str|None- Returns:
Full name as tuple, or None if not found
- get_fuzz_name(name, found_error=False)¶
Fuzzy search for members by name using partial matching Searches across first_name and last_name fields
- Parameters:
name (
str) – Free text name to search for (partial match)- Returns:
Tuple of (first_name, last_name) or None
- Raises:
ValueError – If not found and found_error is True
- get_mojo_name(full_name, found_error=False)¶
Resolve a member name from a free-text full name
Search order
first + last
middle + last (if three parts)
initial 1st letter + last
initial 2nd letter + last (for two-letter initials)
Returns (first_name, last_name) or None
- Parameters:
full_name (
str) – Full name of the member to findfound_error (
bool) – (optional) Raise ValueError if not found
- Return type:
tuple|None- Returns:
Membermojo name if found, else None
- Raises:
ValueError – If not found and found_error is True
- get_name(member_number)¶
Get full name for a given member number
- Parameters:
member_number (
int) – Member number to look up- Return type:
str|None- Returns:
Full name as “First Last”, or None if not found
- get_number(full_name, found_error=False)¶
Find a member number by passed full_name Tries first and last, and then middle last if 3 words, Then initial of first name if initials passed Finnaly a fuzzy lookup is tried
- Parameters:
full_name (
str) – Full name of the memberfound_error (
bool) – (optional) Raise ValueError if not found
- Return type:
int|None- Returns:
Member number if found, else None
- Raises:
ValueError – If not found and found_error is True
- get_number_first_last(first_name, last_name, found_error=False)¶
Find a member number based on first and last name (case-insensitive)
- Parameters:
first_name (
str) – First name of the memberlast_name (
str) – Last name of the memberfound_error (
bool) – (optional): If True, raises ValueError if not found
- Return type:
int|None- Returns:
The member number if found, otherwise None
- Raises:
ValueError – If not found and found_error is True
- get_row(entry_name, entry_value, only_one=True)¶
Retrieve a single or multiple rows matching column = value (case-insensitive)
- Parameters:
entry_name (
str) – Column name to filter byentry_value (
str) – Value to matchonly_one (
bool) – If True (default), return the first matching row If False, return a list of all matching rows
- Return type:
Row|List[Row] |None- Returns:
If only_one=True → a single sqlite3.Row or None
If only_one=False → list of sqlite3.Row (may be empty)
- get_row_multi(match_dict, only_one=True)¶
Retrieve one or many rows matching multiple column=value pairs
- Parameters:
match_dict (
dict) – Dictionary of column names and values to matchonly_one (
bool) – If True (default), return the first matching row If False, return a list of all matching rows
- Return type:
Row|List[Row] |None- Returns:
If only_one=True → a single sqlite3.Row or None
If only_one=False → list of sqlite3.Row (may be empty)
- import_csv(csv_path, merge=False)¶
Import the passed CSV into the encrypted sqlite database
- Parameters:
csv_path (
Path) – Path like path of csv filemerge (
bool) – (optional) If True, merge into existing table. Defaults to False. Form importing current, and expired members as headings are the same.
- member_type_count(membership_type)¶
Count members by membership type string
- Parameters:
membership_type (
str) –the string to match, can use percent to match remaining or preceeding text
Full (match only Full)
Full% (match Full and any words after)
%Full% ( match Full in the middle)
- Return type:
int- Returns:
Number of members that are membership_type
- print_diff(old_table)¶
Print out diff between old and new db
- Parameters:
old_table (
str) – The name the existing table was renamed to
- rename_old_table(existing)¶
If there was an exising table rename for comparison
- Parameters:
existing (
bool) – bool for table exists- Return type:
str- Returns:
the old table name
- run_count_query(sql, params)¶
Generate whole sql query for running on db table for counting and run
- Parameters:
sql (
str) – the sqlite query for matching rowsparams (
tuple) – the paramaters to use for the query
- Return type:
int- Returns:
number of matching rows
- show_table(limit=2)¶
Print the first few rows of the table as dictionaries
- Parameters:
limit (
int) – (optional) Number of rows to display. Defaults to 2
- table_exists()¶
Return True or False if a table exists
- Return type:
bool