The TweetClient
classο
- class InstaTweet.tweetclient.TweetClient(profile, proxies=None)[source]View on GitHubο
Bases:
object
- MAX_HASHTAGS = 5ο
- DEFAULT_KEYS = {'Access Token': 'string', 'Consumer Key': 'string', 'Consumer Secret': 'string', 'Token Secret': 'string'}ο
- __init__(profile, proxies=None)[source]View on GitHubο
Initialize TweetClient using a
Profile
Basically just a wrapper for tweepy. It uses the settings of a profile to initialize the API and send tweets
- Parameters
profile (Profile) β the profile to use when initializing a
tweepy.API
objectproxies (Optional[dict]) β optional proxies to use when making API requests
- get_api()[source]View on GitHubο
Initializes a
API
object using the API keys of the loadedProfile
- Return type
- static get_oauth(api_keys)[source]View on GitHubο
Initializes and returns an
OAuth1UserHandler
object from tweepy using the specified API keys- Parameters
api_keys (dict) β Twitter developer API keys with v1.1 endpoint access
- Return type
- send_tweet(post, hashtags=None)[source]View on GitHubο
Composes and sends a Tweet using an already-downloaded Instagram post
How Tweets are Sent
The
InstaPost.filepath
β set bydownload_post()
β is used as the media sourceThe body of the tweet is then generated by
build_tweet()
- upload_media(post)[source]View on GitHubο
Uploads the media from an already-downloaded Instagram post to Twitter
Note
If the post is a carousel, only the first 4 photos/videos will be uploaded
- build_tweet(post, hashtags=None)[source]View on GitHubο
Uses an
InstaPost
to build the body text of a tweetHow Tweets are Composed
The
caption
is used as a starting pointIf you
add_hashtags()
for the page, it will randomlypick_hashtags()
to includeLastly, the postβs
permalink
is added to the end
Example:
>> post = instatweet.insta.get_user("dailykittenig").posts[0] >> tweet = instatweet.twitter.build_tweet(post) >> print(tweet) carousel support yuh #kitten #kittycat #catlover #petstagram #animals https://www.instagram.com/p/Cjl3UWBOd8k
- static pick_hashtags(hashtags)[source]View on GitHubο
Randomly picks hashtags from the provided list and returns them as a single string
The number of hashtags chosen will either be 1 less than the length of the list (to avoid using the same tags in every tweet), or the value of
MAX_HASHTAGS
, whichever is smaller- Parameters
hashtags (list[str]) β a list of hashtags to randomly choose from
- Example
from InstaTweet import TweetClient >> TweetClient.pick_hashtags(['cat','dog','woof']) "#woof #cat\n"
- Return type
Note
A newline is added to help with formatting & character counting in
build_tweet()