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 users 🠖 download_post() & send_tweet() for any new content 🠖 update the user_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()[source]View on GitHub

InstaTweets all users that have been added to the loaded Profile

Each user’s IG page will be scraped and compared to the scraped list in their USER_MAPPING. Posts that weren’t previously scraped will be downloaded and tweeted

Note

If InstaTweet fails to download_post() or send_tweet(), the USER_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()

get_new_posts(username)[source]View on GitHub

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

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

Instead, the user is “initialized” as follows:
  • Their scraped list will be populated with the ID’s from the most recent posts

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

Parameters

username – the IG username to scrape posts from

Returns

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

Return type

Optional[List[InstaPost]]