whatstk.utils

Library generic utils.


whatstk.utils.chat_merge

Merging chats.

Functions:

merge_chats(dfs)

Merge several chats into a single one.

whatstk.utils.chat_merge.merge_chats(dfs: List[DataFrame]) DataFrame[source]

Merge several chats into a single one.

Can come in handy when you have old exports and new ones, and both have relevant data.

Note: The dataframes must have an index with the timestamps of the messages, as this is required to correctly sort and merge the chats.

Parameters:

dfs (List[pandas.DataFrame]) – List with the chats as DataFrames.

Returns:

pandas.DataFrame – Merged chat.


whatstk.utils.gdrive

Google Drive utils.

Warning

To load chats from google drive, install the library with the corresponding extension (ignore the --upgrade option if you haven’t installed the library):

pip install whatstk[gdrive] --upgrade

Functions:

gdrive_init(client_secret_file[, encoding])

Initialize GDrive credentials.

whatstk.utils.gdrive.gdrive_init(client_secret_file: str, encoding: str = 'utf8') None[source]

Initialize GDrive credentials.

This should only run once before reading a file from Google Drive the first time. Subsequent executions should run seamlessly.

To obtain client_secret_file, follow the instructions from: https://medium.com/analytics-vidhya/how-to-connect-google-drive-to-python-using-pydrive-9681b2a14f20

Notes

Parameters:
  • client_secret_file (str) – Path to clien_secret.json file (Created in Google Console).

  • encoding (str) – Encoding to use for UTF when reading/writing (ex. ‘utf-8’). List of Python standard encodings.


whatstk.utils.exceptions

Library exceptions.

Exceptions:

HFormatError

Raised when hformat could not be found.

RegexError

Raised when regex match is not possible.

exception whatstk.utils.exceptions.HFormatError[source]

Bases: Exception

Raised when hformat could not be found.

exception whatstk.utils.exceptions.RegexError[source]

Bases: Exception

Raised when regex match is not possible.


whatstk.utils.utils

Utils.

Classes:

ColnamesDf()

Access class constants using variable whatstk.utils.utils.COLNAMES_DF.

class whatstk.utils.utils.ColnamesDf[source]

Bases: object

Access class constants using variable whatstk.utils.utils.COLNAMES_DF.

Example

Access constant COLNAMES_DF.DATE:

>>> from whatstk.utils.utils import COLNAMES_DF
>>> COLNAMES_DF.DATE
'date'

Attributes:

DATE

Date column

MESSAGE

Message column

MESSAGE_LENGTH

Message length column

USERNAME

Username column

DATE = 'date'

Date column

MESSAGE = 'message'

Message column

MESSAGE_LENGTH = 'message_length'

Message length column

USERNAME = 'username'

Username column