The InstaTweet class

Not to be confused with the package, the InstaTweet class is the main point of interaction for a user of the package

class InstaTweet.instatweet.InstaTweet(profile)[source]View on GitHub

Bases: object

Uses the settings from a Profile to do the actual InstaTweeting

You might be wondering, what’s InstaTweeting? According to TDK Dictionary:

InstaTweet (verb):

To load a Profile 🠖 scrape posts from its Instagram pages 🠖 download_post() & send_tweet() for any new content 🠖 update the page_map 🠖 save() the profile if it exists

Example Sentence

Oh, you lost 700 Twitter followers after you shared your IG post? Well maybe if people actually saw the picture and not just the caption your tweet would’ve been less creepy. You should’ve InstaTweeted it.

__init__(profile)[source]View on GitHub

Initializes InstaTweet using a fully configured Profile

The Profile will be used to initialize an InstaClient and TweetClient

Note

InstaTweet won’t validate() the Profile settings until you call start()

Parameters

profile (Profile) – the Profile to use for InstaTweeting

classmethod load(profile_name, local=True)[source]View on GitHub

Loads a profile by name

Parameters
  • profile_name (str) – name of the Profile to load

  • local (bool) – whether the profile is saved locally (default) or remotely on a database

Return type

InstaTweet

get_proxies()[source]View on GitHub

Retrieve proxies using the loaded Profile’s proxy_key

Return type

Optional[Dict]

get_insta_client()[source]View on GitHub

Initializes an InstaClient using the loaded Profile settings

Return type

InstaClient

get_tweet_client()[source]View on GitHub

Initializes an TweetClient using the loaded Profile settings

Return type

TweetClient

start(max_posts=12)[source]View on GitHub

InstaTweets all pages that have been added to the loaded Profile

The most recent posts from each page will be scraped, then compared to the scraped list in the PAGE_MAPPING to determine which are new.

Up to max_posts new posts from each page will then be downloaded and tweeted

Note

If InstaTweet fails to download_post() or send_tweet(), the PAGE_MAPPING won’t be updated

  • This ensures that failed repost attempts are retried in the next call to start()

If a save file for the Profile already exists, successful reposts will trigger a call to save()

Parameters

max_posts (int) – the maximum number of new posts to download and tweet per page

get_new_posts(insta_page)[source]View on GitHub

Scrapes recent posts from an Instagram page and returns all posts that haven’t been tweeted yet

NOTE: If a page’s scraped list is empty, no posts will be returned.

Instead, the page is “initialized” as follows:

  • The scraped list will be populated with the ID’s from the most recent posts

  • These IDs are then used in future method calls to determine which posts to tweet

Parameters

insta_page (str) – the Instagram page to scrape posts from

Returns

a list of posts that haven’t been tweeted yet, or nothing at all (if page is only initialized)

Return type

Optional[List[InstaPost]]