marcopompili / django-instagram

Instagram application for Django.
BSD 3-Clause "New" or "Revised" License
76 stars 27 forks source link
django instagram scraper

django-instagram

⚠️ This project should be considered abandoned. To embed IG content you should go through Instagram official API.

A Django application that allows to use some template tags for displaying content from an Instagram public profile.

Requirements

Installation

Install Django with your favourite Linux packaging system or you can use pip for installing python packages, if Django is not an official package for your distribution:

pip install django

Use pip to install Django Instagram:

pip install django-instagram

Pip should take care of the package dependencies for Django Instagram.

Configuration

Add the application to INSTALLED_APPS:

INSTALLED_APPS = (
                  ...
                  'sorl.thumbnail', # required for thumbnail support
                  'django_instagram',)

Rebuild your application database, this command depends on which version of Django you are using.

In Django 2.0 (recommended):

python manage.py makemigrations django_instagram

Them migrate the db:

python manage.py migrate

Usage

The instagram_user_recent_media brings into context two objects:

A Django urls.py example using a TemplateView View class with a context variable called instagram_profile_name:

from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', TemplateView.as_view(template_name='index.html', extra_context={
        "instagram_profile_name": "amd"
    })),
]

You can display the data contained in recent_media list like this:

<!DOCTYPE html>

{% load instagram_client %}

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ instagram_profile_name|capfirst }} Instagram feed</title>
</head>
<body>
<h1>{{ instagram_profile_name|capfirst }} Instagram Feed</h1>
<div id="django_recent_media_wall">
    {% instagram_user_recent_media instagram_profile_name %}
    {% for media in recent_media %}
        <div class="django_instagram_media_wall_item">
            <a href="https://github.com/marcopompili/django-instagram/blob/master//instagram.com/p/{{ media.shortcode }}" target="_blank">
                <img src="https://github.com/marcopompili/django-instagram/raw/master/{{ media.thumbnail_src }}"/>
                <span>{{ media.edge_media_to_caption.edges.0.node.text }}</span>
            </a>
        </div>
    {% endfor %}
</div>
<p>Got from instagram</p>
</body>
</html>

There are also two inclusion tags that includes an example of how to parse data from Instagram, you can also use them like this:

{% load instagram_client %}

<h1>Instagram media wall</h1>
{% instagram_recent_media_wall username="intel" %}

<h1>Instagram sliding box</h1>
{% instagram_recent_media_box username="intel" %}

Filters

As you may have noticed some filters can be used for sizing the pictures. Make sure you have sorl.thumbnail in the INSTALLED_APPS to use these.

Here is the list of the usable fitlers:

For standard size:

{% for media in recent_media %}
...
<img src="https://github.com/marcopompili/django-instagram/raw/master/{{ media.thumbnail_src|standard_size }}"/>
...
{% endfor %}

For low resolution images:

{% for media in recent_media %}
...
<img src="https://github.com/marcopompili/django-instagram/raw/master/{{ media.thumbnail_src|low_resolution }}"/>
...
{% endfor %}

For thumbnail size:

{% for media in recent_media %}
...
<img src="https://github.com/marcopompili/django-instagram/raw/master/{{ media.thumbnail_src|thumbnail }}"/>
...
{% endfor %}

Releases