social module
- class lib.social.Facebook
Bases:
lib.social.Graph
Facebook super class.
- image_endpoint
GraphAPI node to upload images to, in this case ‘photos’.
- Type
str
- post_endpoint
GraphAPI node to post to the page feed, ‘feed’.
- Type
str
- post(bundle: dict[str, Union[list[str], dict[str, list[str]]]]) → None
Post to Facebook.
- class lib.social.Graph(platform: str)
Bases:
lib.social.Platform
Meta class for GraphAPI platforms Facebook and Instagram.
- api
- Type
facebook.GraphAPI
- id
The identifier for the chosen platform.
- Type
str
- _auth() → facebook.GraphAPI
Authorizes access to the Graph API for Facebook/Instagram.
- _bundle_prep(bundle: dict[str, Union[list[str], dict[str, list[str]]]]) → tuple[str, list[str]]
Prepares the AgitProp.bundle for use for Facebook.
- Parameters
bundle (dict) – AgitProp.bundle
- Returns
The prepared caption string and list of media.
- Return type
tuple[str, list]
- _check_auth() → None
Verifies if the API access token is valid. If not, it will refresh.
- _media_prep(media: list, endpoint: str) → list
Uploads the bundle media to Facebook, replacing the media filepaths with their respective IDs.
- Parameters
media (list) –
- Return type
list
- refresh_auth() → None
Refreshes the Graph API access token, saving it in the user config.
- class lib.social.Instagram
Bases:
lib.social.Graph
Instagram super class.
- image_endpoint
GraphAPI node to upload images to, in this case ‘media’.
- Type
str
- post_endpoint
GraphAPI node to post the media container, ‘media_publish’.
- Type
str
- post(bundle: dict[str, Union[list[str], dict[str, list[str]]]]) → None
Post to Instagram.
- class lib.social.Platform(platform: str)
Bases:
object
Meta class for social media platforms.
- conf
User configuration file.
- Type
dict
- auth
- Type
dict
- _check_resize(path: pathlib.Path) → pathlib.Path
Checks if there exists a resized image. If not, downsizes it.
- Returns
path – The filepath to the upload-ready image.
- Return type
Path
- class lib.social.Twitter
Bases:
lib.social.Platform
Twitter super class.
- api
- Type
tweepy.API
- _auth() → tweepy.api.API
Authorizes access to Twitter.
- _bundle_prep(bundle: dict[str, Union[list[str], dict[str, list[str]]]]) → list[tuple[str, list[pathlib.Path]]]
Prepares the AgitProp.bundle for use for Twitter.
Involved as captions can require individual tweets with non-equal number of graphics, all split by language.
- Parameters
bundle (dict) – AgitProp.bundle
- Returns
posts – The prepared caption strings and lists of media.
- Return type
list[tuple[str, list[Path]]]
- _media_prep(posts: list[tuple[str, list[pathlib.Path]]]) → list[tuple[str, list[tweepy.models.Media]]]
Uploads the bundle media to Twitter, replacing the media filepaths with their respective Twitter IDs.
- Parameters
posts (list[tuple[str, list[Path]]]) –
- Returns
posts
- Return type
list[tuple[str, list[tweepy.models.Media]]]
- post(bundle: dict[str, Union[list[str], dict[str, list[str]]]]) → None
Posts the set of Tweets as replies to itself on Twitter.
- Parameters
bundle (dict) – AgitProp.bundle
- lib.social.combine_caption(captions: dict) → str
Takes the individual caption items and creates a formatted string.
- Parameters
captions (dict) –
- Return type
str
- lib.social.verify_caption_length(captions: dict[str, list[str]]) → Union[str, dict[str, list[str]]]
Verifies that the captions fit on all social media platforms.
- Parameters
captions (dict) –
- Returns
Verified caption will return as a dict. In a Rust-like manner, the exception (in this case a str with the exception message) gets passed to the parent function to handle.
- Return type
Union[dict, str]