• No results found

From sources

In document instatools Documentation (Page 7-24)

The sources for instatools can be downloaded from theGithub repo.

You can either clone the public repository:

$ git clone git://github.com/sentrip/instatools

Or download thetarball:

$ curl -OL https://github.com/sentrip/instatools/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

4 Chapter 2. Installation

CHAPTER 3

Usage

To use instatools in a project:

import instatools

6 Chapter 3. Usage

CHAPTER 4

instatools

4.1 instatools package

4.1.1 Subpackages

instatools.instagram package Submodules

instatools.instagram.api module instatools.instagram.feeds module

class instatools.instagram.feeds.FeedReader(api, feed_type, *args, reset_after=86400) Bases: object

reset()

class instatools.instagram.feeds.Feeds(api=None) Bases: object

liked

location(search) popular

saved tag(search) timeline user(search) user_tags(search)

instatools.instagram.hub module

class instatools.instagram.hub.Hub(api=None) Bases: object

activity explore

following_activity inbox

megaphone share_inbox

instatools.instagram.instagram module

Public api for Instagram

class instatools.instagram.instagram.Instagram(username=None, password=None, ses-sion=None)

Bases: object approve(user_id) block(user_id) comment(post_id, text)

direct_message(recipients, msg)

direct_share(post_id, recipients, msg=None) edit_caption(post_id, new_caption)

follow(user_id)

get_comments(post_id)

get_followers(user_id=None) get_following(user_id=None) get_friendship(user_id) get_geo_media(user_id) get_likers(post_id) get_post(post_id) get_story(user_id) get_user(user_id) get_username(username) ignore(user_id)

like(post_id) login()

Login to Instagram with account credentials provided in __init__

8 Chapter 4. instatools

instatools Documentation, Release 0.1.8

logout()

Logout of currently logged-in account password

Password of Instagram account post(*args)

remove_comment(post_id, comment_id) remove_post(post_id)

remove_tag(post_id) save(post_id)

switch_user(username=None, password=None, session=None) Switches current account username and password - requires login unblock(user_id)

unfollow(user_id) unlike(post_id) unsave(post_id) username

Username of Instagram account username_id

User-id of Instagram account

class instatools.instagram.instagram.Users(api=None, list_type=None) Bases: object

Class representing new and removed users current

update()

instatools.instagram.profile module

class instatools.instagram.profile.Profile(api=None) Bases: object

biography

change_password(new_password) change_profile_picture()

edit(phone, email, *, full_name=None, username=None, url=None, biography=None, gender=None) external_url

follow_requests full_name

remove_profile_picture() set_private()

set_public()

threads(thread, cursor=None)

instatools.instagram.search module

class instatools.instagram.search.Search(api=None) Bases: object

facebook(users) locations(location) tags(tag)

users(username)

instatools.instagram.upload module Module contents

class instatools.instagram.Instagram(username=None, password=None, session=None) Bases: object

approve(user_id) block(user_id) comment(post_id, text)

direct_message(recipients, msg)

direct_share(post_id, recipients, msg=None) edit_caption(post_id, new_caption)

follow(user_id)

get_comments(post_id)

get_followers(user_id=None) get_following(user_id=None) get_friendship(user_id) get_geo_media(user_id) get_likers(post_id) get_post(post_id) get_story(user_id) get_user(user_id) get_username(username) ignore(user_id)

like(post_id) login()

Login to Instagram with account credentials provided in __init__

10 Chapter 4. instatools

instatools Documentation, Release 0.1.8

logout()

Logout of currently logged-in account password

Password of Instagram account post(*args)

remove_comment(post_id, comment_id) remove_post(post_id)

remove_tag(post_id) save(post_id)

switch_user(username=None, password=None, session=None) Switches current account username and password - requires login unblock(user_id)

unfollow(user_id) unlike(post_id) unsave(post_id) username

Username of Instagram account username_id

User-id of Instagram account

4.1.2 Submodules

4.1.3 instatools.api module

Wrappers for interactions with Instagram API class instatools.api.ApiMethod(api)

Bases: object

action(path, *args, max_attempts=10, return_key=”, extra=None, method=’POST’, headers=None, params=None, data=None)

Parameters

• path –

• args –

• max_attempts –

• return_key –

• extra –

• method –

• headers –

• params –

• data – Returns

feed(feed_type, *args, seen=None, raw=False) Parameters

• feed_type –

• args –

• seen –

• raw – Returns

form(path, bodies, boundary, params=None, return_key=”) Parameters

• path –

• bodies –

• boundary –

• params –

• return_key – Returns

instatools.api.requires_login(func)

4.1.4 instatools.cache module

Response caching for testing integration with instatools

class instatools.cache.DataBaseCache(db_path, default_factories=None) Bases: object

clear() delete(key) get(key) set(key, value)

instatools.cache.clear(data_dir) instatools.cache.read(data_dir) instatools.cache.record(data_dir)

4.1.5 instatools.models module

class instatools.models.Comment(api, json) Bases:instatools.models.Model

classmethod parse(api, json, extra=None) remove()

reply(msg)

class instatools.models.Location(api, json) Bases:instatools.models.Model

12 Chapter 4. instatools

instatools Documentation, Release 0.1.8

classmethod parse(api, json, extra=None) class instatools.models.Model(api, json)

Bases: object

classmethod parse(api, json, extra=None)

classmethod parse_list(api, json_list, extra=None) class instatools.models.ModelFactory

Bases: object comment

alias ofComment default

alias ofModel friendship_status

alias ofRelationship item

alias ofPost location

alias ofLocation post

alias ofPost ranked_item

alias ofPost relationship

alias ofRelationship user

alias ofUser

class instatools.models.Post(api, json) Bases:instatools.models.Model comments

download() likers

classmethod parse(api, json, extra=None) save()

share(user_ids, msg=None) unsave()

upload()

class instatools.models.Relationship(api, json) Bases:instatools.models.Model

classmethod parse(api, json, extra=None) class instatools.models.User(api, json)

Bases:instatools.models.Model approve()

block()

direct_message(msg)

direct_share(post_id, msg=None) feed

follow() followers following ignore()

classmethod parse(api, json, extra=None) unblock()

unfollow()

4.1.6 instatools.session module

Instagram Session class provides bare minimum to make authenticated, rate_limited requests to the Instagram API class instatools.session.Session(username=None, password=None, session=None)

Bases: object

Class representing the request-making Session of a single Instagram user static build_form_body(bodies, boundary)

Parameters

• bodies –

• boundary – Returns

static configure_data(width, height, upload_id, caption, video=False) static configure_data_photo(width, height)

static configure_data_video(duration) device_id = None

exponential_sleep_increase = 2

form_data_for_message(recipients, text=None) Parameters

• recipients –

• text – Returns

static form_headers(boundary) Parameters boundary – Returns

login()

Login to Instagram with account credentials provided in __init__

14 Chapter 4. instatools

instatools Documentation, Release 0.1.8

login_data(cookies)

Using cookies provided, gives data to send to Instagram for login approval :param cookies: cookies from login challenge :return: dict: data to use for login

logout()

Logout of currently logged-in account password = None

paths = {'approve': 'friendships/approve/{}/', 'autocomplete_users': 'friendships/autocomplete_user_list', 'block': 'friendships/block/{}/', 'change_password': 'accounts/change_password/', 'change_profile_picture': 'accounts/change_profile_picture/', 'comment': 'media/{}/comment/', 'comments': 'media/{}/comments/', 'configure': 'media/configure', 'create_post': '', 'direct_link': 'direct_v2/threads/broadcast/link/', 'direct_message': 'direct_v2/threads/broadcast/text/', 'direct_share': 'direct_v2/threads/broadcast/media_share/', 'direct_threads': 'direct_v2/threads/{}/', 'edit_profile': 'accounts/edit_profile/', 'explore': 'discover/explore', 'expose': 'qe/expose', 'facebook_search': 'fbsearch/topsearch', 'follow': 'friendships/create/{}/', 'followers': 'friendships/{}/followers', 'following': 'friendships/{}/following', 'friendship': 'friendships/show/{}/', 'geo_media': 'maps/user/{}', 'ignore': 'friendships/ignore/{}/', 'inbox': 'direct_v2/inbox', 'like': 'media/{}/like/', 'liked': 'feed/liked', 'likers': 'media/{}/likers/', 'location_feed': 'feed/location/{}/', 'location_search': 'fbsearch/places', 'login': 'accounts/login/', 'login_challenge': 'si/fetch_headers/', 'logout': 'accounts/logout/', 'megaphone': 'megaphone/log', 'pending': 'friendships/pending', 'popular': 'feed/popular', 'post': 'media/{}/info/', 'profile': 'accounts/current_user/', 'recent_activity': 'news/inbox', 'recent_following_activity': 'news', 'remove_comment': 'media/{}/comment/{}/delete/', 'remove_post': 'media/{}/delete/', 'remove_profile_picture': 'accounts/remove_profile_picture/', 'remove_tag': 'media/{}/remove/', 'save': 'media/{}/save/', 'saved': 'feed/saved', 'set_phone_name': 'accounts/set_phone_and_name/', 'set_private': 'accounts/set_private/', 'set_public': 'accounts/set_public/', 'share_inbox': 'direct_share/inbox', 'story': 'feed/user/{}/reel_media', 'tag_feed': 'feed/tag/{}/', 'tag_search': 'tags/search', 'timeline': 'feed/timeline', 'unblock': 'friendships/unblock/{}/', 'unfollow': 'friendships/destroy/{}/', 'unlike': 'media/{}/unlike/', 'unsave': 'media/{}/unsave/', 'upload_photo': 'upload/photo', 'upload_video': 'upload/video', 'user': 'users/{}/info/', 'user_feed': 'feed/user/{}/', 'user_search': 'users/search', 'user_tags': 'usertags/{}/feed', 'username': 'users/{}/usernameinfo'}

rank_token

relog_after_failed = 5

request(method, url, *, params=None, data=None, return_json=True, **kwargs) Parameters

• method –

• url –

• params –

• data –

• return_json –

• kwargs – Returns

request_safely(*args, max_attempts=0, **kwargs)

Make a safe request that returns correct results or dies trying! Keeps requesting with exponential back-off until requests_to_break is reached, at which point each consecutive request is circuit-broken and waits sleep_on_breakseconds until a successful request is made, or until relog_after_failed circuit-broken re-quests are made, at which point the client re-logs and begins the whole cycle again. :param args: :param max_attempts: :param kwargs: :return:

requests_to_break = 10 session_data

set_proxy(proxy)

Set proxy for all requests made with this session :param proxy: str: proxy - format:

“user:password@ip:port” OR “ip:port”

setup(username, password, session)

Setup session variables by username/password or by previous session :param username: :param password:

:param session: :return:

sleep_on_break = 600 sleep_on_page = 0.5

switch_user(username=None, password=None, session=None) Switches current account username and password - requires login token = None

upload_data_photo(upload_id, photo_file_object) static upload_headers(content_type, video=False)

Parameters

• content_type –

• video – Returns url(path, *args)

Return url for api path formatted with args username = None

username_id = None uuid = None

wait_limit(url)

Parameters url – Returns

instatools.session.generate_device_id(seed) Generate new device id

instatools.session.generate_signature(data)

Generates signed signature of POST data using SIG_KEY (signing key) :param data: dict: POST data :return:

str: data to append to request url

instatools.session.generate_upload_id() Generate new upload id :return:

instatools.session.generate_uuid(typ) Generate new uuid :param typ: :return:

4.1.7 instatools.utils module 4.1.8 Module contents

Top-level package for instatools.

class instatools.Instagram(username=None, password=None, session=None) Bases: object

approve(user_id) block(user_id) comment(post_id, text)

direct_message(recipients, msg)

direct_share(post_id, recipients, msg=None) edit_caption(post_id, new_caption)

follow(user_id)

get_comments(post_id)

get_followers(user_id=None) get_following(user_id=None) get_friendship(user_id) get_geo_media(user_id)

16 Chapter 4. instatools

instatools Documentation, Release 0.1.8

get_likers(post_id) get_post(post_id) get_story(user_id) get_user(user_id) get_username(username) ignore(user_id)

like(post_id) login()

Login to Instagram with account credentials provided in __init__

logout()

Logout of currently logged-in account password

Password of Instagram account post(*args)

remove_comment(post_id, comment_id) remove_post(post_id)

remove_tag(post_id) save(post_id)

switch_user(username=None, password=None, session=None) Switches current account username and password - requires login unblock(user_id)

unfollow(user_id) unlike(post_id) unsave(post_id) username

Username of Instagram account username_id

User-id of Instagram account

18 Chapter 4. instatools

CHAPTER 5

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

5.1 Types of Contributions

5.1.1 Report Bugs

Report bugs athttps://github.com/sentrip/instatools/issues.

If you are reporting a bug, please include:

• Your operating system name and version.

• Any details about your local setup that might be helpful in troubleshooting.

• Detailed steps to reproduce the bug.

5.1.2 Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

5.1.3 Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

5.1.4 Write Documentation

instatools could always use more documentation, whether as part of the official instatools docs, in docstrings, or even on the web in blog posts, articles, and such.

5.1.5 Submit Feedback

The best way to send feedback is to file an issue athttps://github.com/sentrip/instatools/issues.

If you are proposing a feature:

• Explain in detail how it would work.

• Keep the scope as narrow as possible, to make it easier to implement.

• Remember that this is a volunteer-driven project, and that contributions are welcome :)

In document instatools Documentation (Page 7-24)

Related documents