Helper Types
Auxiliar functions and classes that serve general purposes.
Constants
- general_func.MAX_POSTS_LIMIT: int = 1000
Classes
- class pykemo._aux.aux_classes.FileHashResult(*, file, posts, disc)
Result used when querying for a file using its hash.
- Parameters:
file (
File) – The file itself.posts (list[
Post]) – All the normal posts where this file appears.disc (list[
DiscordMessage]) – All the discord messages where this file is.
- classmethod empty()
- Returns:
An instance of the result with empty fields.
- Return type:
Functions
Module for auxiliar functions.
- async pykemo.general.general_func.get_api_version(kemo_session)
Convenience function to get the last hash of the current API version.
- Parameters:
kemo_session (
KemoSession) – The Kemono Session to use.- Returns:
The last commit hash of the API.
- Return type:
str
- async pykemo.general.general_func.get_creator(service, creator_id, kemo_session)
Tries to retrieve a creator with the given ID and service.
- Parameters:
service (
ServiceLike) – The service of the creator.creator_id (str) – The ID of the creator.
kemo_session (
KemoSession) – The Kemono Session to use.
- Returns:
The creator instance, if found. Otherwise returns
None.- Return type:
Optional[
Creator]
- async pykemo.general.general_func.get_creator_links(service, creator_id)
Retrieves a list that is the other accounts of a creator, should it have any with other services, for example.
- Parameters:
service (
ServiceLike) – The service of the creator.creator_id (str) – The ID of the creator.
- Returns:
A list of the creators associated with this one.
- Return type:
list[
Creator]
- async pykemo.general.general_func.get_creators(kemo_session)
Gets all the creators.
Warning
There is currently no limitations to this function. It will really try to fetch ALL the creators on the site. If you do not explicitly need this, do not use it.
- Parameters:
kemo_session (
KemoSession) – The Kemono Session to use.- Returns:
The list of all creators.
- Return type:
list[
Creator]
- async pykemo.general.general_func.get_file_hash(hash, kemo_session)
Search a file by hash. Also tries to retrieve posts where such file is present.
- Parameters:
hash (
str) – The query hash to search with.session (
KemoSession) – The Kemono Session to use.kemo_session (KemoSession)
- Returns:
The result of the query.
- Return type:
- async pykemo.general.general_func.get_post(service, post_id, kemo_session)
Tries to fetch a post by its service and ID, automatically searching for its creator.
- Parameters:
service (
ServiceLike) – The service the post falls under.post_id (
PostID) – The ID of the specific post.kemo_session (
KemoSession) – The Kemono Session to use.
- Returns:
The loaded post, if it was found. If not, returns
None.- Return type:
Optional[
Post]
- async pykemo.general.general_func.get_posts(query=None, *, max_posts=50, before=None, since=None, tags=None, kemo_session)
Gets all posts that coincide with the given parameters.
- Parameters:
query (Optional[
str]) – A query string to use in the search.max_posts (
int) – The max number of posts to look through. This is NOT necessarily the number of posts to enter the lists.before (Optional[
datetime.datetime]) – Include only posts before this date, defaults toNone.since (Optional[
datetime.datetime]) – Include only posts after and including this date, defaults toNone.tags (list[
TagLike], optional) – The tags to filter the search by, defaults toNone.kemo_session (
KemoSession) – The Kemono Session to use.
- Returns:
The list of posts of the query.
- Return type:
list[
Post]
- async pykemo.general.general_func.login(user, password)
An alias for logging an automatically deciding which account rank is returned.
- Parameters:
user (
str) – The username to try to login with.password (
str) – The password to try to login with.
- Raises:
InvalidLogin – The login had incorrect data.
AlreadyLoggedIn – The user is already logged in.
LoginError – Another error ocurred.
- Returns:
Any of the possible account types, already logged-in.
- Return type:
AccountType
- async pykemo.general.general_func.random_post(session)
Tries to retrieve a random post from the site.
- Parameters:
session (
KemoSession) – The Kemono Session to use for the request.- Returns:
If a creator is found, retrieve and create a
Postinstance, otherwise returnNone.- Return type:
Optional[
Post]
- async pykemo.general.general_func.register(user, password)
An alias for registering an account. Is is assumed each new account is born as a consumer.
- Parameters:
user (str)
password (str)
- Return type:
- async pykemo.general.general_func.save_posts(path, posts, *, force=True, verbose=True)
Tries to save many posts in bulk.
Warning
The connection may close in between if it takes too long, but it reconnects automatically.
- Parameters:
path (
PathLike) – The path to be used to save all the contents of the posts.posts (Iterable[
Post]) – The posts to be saved.force (
bool, optional) – Wether to overwrite existing files, defaults toTrueverbose (
bool, optional) – Wether to track progress, defaults toTrue
- Returns:
Trueif all downloads were sucessful, orFalseif not.- Return type:
bool