Tools
Helper modules for Chopin
Dates
Date range utilitaries.
parse_release_date(date)
Parse the release date depending on the level of detail available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
str
|
An input date, as a string |
required |
Returns:
| Type | Description |
|---|---|
date
|
A formatted date, with the datetime library. |
Source code in chopin/tools/dates.py
read_date(date)
Read a date from a string tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
tuple[str | None, str | None] | None
|
The date to parse |
required |
Returns:
| Type | Description |
|---|---|
ReleaseRange | None
|
A parsed date (if it exists), e.g. a range of two datetime objects. |
Examples:
>>> read_date('10/01/2023', '10/02/2023')
(datetime.datetime(2023, 1, 10, 0, 0), datetime.datetime(2023, 2, 10, 0, 0))
>>> read_date('10/01/2023', )
(datetime.datetime(2023, 1, 10, 0, 0), datetime.datetime.now()
Source code in chopin/tools/dates.py
Dictionaries
Utilities to help with dictionaries.
flatten_dict(dictionary)
Flatten a dictionary with potential nested dictionaries, into a single dictionary.
Example
will become:Source code in chopin/tools/dictionaries.py
Strings
Utilites to help deal with strings.
decode(encoded_string, alphabet=BASE62)
Decode a Base X encoded string into the number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_string
|
The encoded string |
required | |
alphabet
|
Alphabet to use for decoding |
BASE62
|
Returns:
| Type | Description |
|---|---|
str
|
The decoded string |
Source code in chopin/tools/strings.py
extract_uri_from_playlist_link(playlist_link)
Parse a playlist link and returns the playlist URI. The playlist URI is later used to query the Spotify API.
Example
https://open.spotify.com/playlist/37i9dQZF1DWWv8B5EWK7bn?si=8d52c3fef8d74064 becomes 37i9dQZF1DWWv8B5EWK7bn
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
playlist_link
|
str
|
https link to a Spotify playlist. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The playlist URI |
Source code in chopin/tools/strings.py
match_strings(strings)
Check if all strings match.
They match if their lowercase, unicode stripped-off characters versions are similar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strings
|
list[str]
|
A list of strings to match |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all strings are the same (minus lowercase and unicode special character differences) |
Source code in chopin/tools/strings.py
owner_is_spotify(uri)
Test if the given URI is owned by spotify.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
URI to test |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if 'spotify' is the owner of the URI item. |
Source code in chopin/tools/strings.py
simplify_string(text)
Simplify a string: lowercase, and no emojis.