diff --git a/docs/codesnippets.rst b/docs/codesnippets.rst index 2b6d944..58430a6 100644 --- a/docs/codesnippets.rst +++ b/docs/codesnippets.rst @@ -82,6 +82,15 @@ See also :class:`Post`, :meth:`Instaloader.download_post`, Discussed in :issue:`113`. +Top X Posts of User +------------------- + +With Instaloader, it is easy to download the few most-liked pictres of a user. + +.. literalinclude:: codesnippets/194_top_x_of_user.py + +Discussed in :issue:`194`. + Upgrade Images by Local Copies ------------------------------ diff --git a/docs/codesnippets/194_top_x_of_user.py b/docs/codesnippets/194_top_x_of_user.py new file mode 100644 index 0000000..7a7f4c9 --- /dev/null +++ b/docs/codesnippets/194_top_x_of_user.py @@ -0,0 +1,15 @@ +from itertools import islice +from math import ceil + +from instaloader import Instaloader, Profile + +PROFILE = ... # profile to download from +X_percentage = 10 # percentage of posts that should be downloaded + +L = Instaloader() + +profile = Profile.from_username(L.context, PROFILE) +posts_sorted_by_likes = sorted(profile.get_posts(), key = lambda p: p.likes + p.comments) + +for post in islice(posts_sorted_by_likes, ceil(profile.mediacount * X_percentage / 100)): + L.download_post(post, PROFILE) diff --git a/docs/codesnippets/92_import_firefox_session.py b/docs/codesnippets/92_import_firefox_session.py new file mode 100644 index 0000000..0e05d2d --- /dev/null +++ b/docs/codesnippets/92_import_firefox_session.py @@ -0,0 +1,23 @@ +from glob import glob +from os.path import expanduser +from sqlite3 import connect + +from instaloader import ConnectionException, Instaloader + +# FIREFOXCOOKIEFILE = "/home/alex/.mozilla/firefox/l96w6b90.default/cookies.sqlite" +FIREFOXCOOKIEFILE = glob(expanduser("~/.mozilla/firefox/*.default/cookies.sqlite"))[0] + +instaloader = Instaloader(max_connection_attempts=1) +instaloader.context._session.cookies.update(connect(FIREFOXCOOKIEFILE) + .execute("SELECT name, value FROM moz_cookies " + "WHERE baseDomain='instagram.com'")) + +try: + username = instaloader.test_login() + if not username: + raise ConnectionException() +except ConnectionException: + raise SystemExit("Cookie import failed. Are you logged in successfully in Firefox?") + +instaloader.context.username = username +instaloader.save_session_to_file() diff --git a/docs/contributing.rst b/docs/contributing.rst index 80e643d..063ac00 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -17,12 +17,14 @@ Reporting Bugs If you encounter a bug, do not hesitate to report it in our `Issue Tracker `__. Since Instaloader is actively developed, the majority of bugs is fixed within only -**3 days** after being reported. When reporting a problem, please keep the +**4 days** after being reported. When reporting a problem, please keep the following in mind: - Ensure you **use the latest version** of Instaloader. The currently-installed version can be found out with ``instaloader --version``. +- Check whether there is a valid solution in our :ref:`troubleshooting` section. + - Briefly **check whether the bug has already been reported**. If you find an issue reporting the same bug you encountered, comment there rather than opening a new issue. However, if unsure, please create a new issue. diff --git a/docs/index.rst b/docs/index.rst index b68a691..8d3eb8e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -60,6 +60,7 @@ Instaloader Documentation cli-options as-module codesnippets + troubleshooting contributing Useful Links diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst new file mode 100644 index 0000000..3069c8e --- /dev/null +++ b/docs/troubleshooting.rst @@ -0,0 +1,60 @@ +.. _troubleshooting: + +Troubleshooting +=============== + +.. highlight:: python + +429 - Too Many Requests +----------------------- + +Instaloader has a logic to keep track of its requests to Instagram and to obey +their rate limits. Since they are nowhere documented, we try them out +experimentally. We have a daily cron job running to confirm that Instaloader +still stays within the rate limits. Nevertheless, the rate control logic assumes +that + +- at one time, Instaloader is the only application that consumes requests. I.e. + neither the Instagram browser interface, nor a mobile app, nor another + Instaloader instance is running in parallel, + +- no requests had been consumed when Instaloader starts. + +The latter one implies that restarting or reinstantiating Instaloader often +within short time is prone to cause a 429. When a request is denied with a 429, +Instaloader retries the request as soon as the temporary ban is assumed to be +expired. In case the retry continuously fails for some reason, which should not +happen in normal conditions, consider adjusting the +:option:`--max-connection-attempts` option. + +**"Too many queries in the last time"** is not an error. It is a notice that the +rate limit has almost been reached, according to Instaloader's own rate +accounting mechanism. We regularly adjust this mechanism to match Instagram's +current rate limiting. + +Login error +----------- + +Instaloader's login *should* work fine, both with and without +Two-Factor-Authentication. It also supports handling the *checkpoint challenge*, +issued when Instagram suspects authentication activity on your account, by +pointing the user to an URL to be opened in a browser. + +Nevertheless, in :issue:`92` users report problems with logging in. To still use +Instaloader's logged-in functionality, you may use the following script to +workaround login problems by importing the session cookies from Firefox and +bypassing Instaloader's login. + +.. literalinclude:: codesnippets/92_import_firefox_session.py + +To use this, + +#. login to Instagram in Firefox, + +#. execute the snippet, + +#. then, ``instaloader -l USERNAME`` should work fine. + +If you do not use your default firefox profile, or your operating system has the +paths differently set up, you may have to alter the ``FIREFOXCOOKIEFILE`` +variable first.