skip to navigation
skip to content

django-last-social-activity 0.2.1

A simple application for Django to fetch the last posts of your social network profiles in your site.

django-last-social-activity

A simple application for Django to fetch the last posts of your social network profiles in your site.

Introduction

This package allows you to fetch your last status from your favorite social networks without having to reimplement any functionality or integrating them on the browser side.

The development repository is https://github.com/intelligenia/django-last-social-activity.

The main aim of this software is having Django template tags ready to load your last posts in templates:

{# Load django-last-social-activity template tags #}
{% load last_social_activity %}

<div class="my-social-networks">
  {# Get the last 10 items of your RSS 'myblog' as defined in settings.py #}
  {% last_rss_items 'myblog' 10 %}

  {# Get the last 3 posts of your Facebook wall #}
  {% last_facebook_posts 3 %}

  {# Get the last 8 tweets #}
  {% last_tweeets 8 %}

  {# Get the last 12 images of Instagram #}
  {% last_instagram_media 12 %}

  {# Get the last 15 pins of Pinterest #}
  {% last_pinterest_pins 15 %}

  {# Get the last 25 photos of 500px #}
  {% last_fivehundred_media 25 %}

  {# Get the last 5 photos of flickr #}
  {% last_flickr_media 5 %}
</div>

The idea is personalize the default templates in your templates folder as you need.

Installation

This package is in pypi so you can install it easily using pip command:

pip install django-last-social-activity

or install it from this GitHub repository if you want last features of the master branch:

# Master will allways be stable
pip install https://github.com//intelligenia/django-last-social-activity/archive/master.zip

Dependencies

This package depends on some other Python packages:

  • beautifulsoup4
  • python-dateutil
  • python-twitter
  • requests

They are included in the requirements of this package so you won’t have to install them by hand.

Configuration

Django settings.py

The first step is include the application last_social_activity to your INSTALLED_APPS tuple:

INSTALLED_APPS = (
  #...
  "last_social_activity"
  #...
)

The second step is configuring what social networks you want to include in your site.

Put this dictionary in your settings.py file filling the.

LAST_SOCIAL_ACTIVITY_CREDENTIALS = {
    "twitter": {
        "profile_url": "<your twitter profile>",
        "username": "<your twitter username>",
        "consumer_key": "<consumer key>",
        "consumer_secret": "<consumer secret>",
        "access_token_key": "<access token key>",
        "access_token_secret": "<access token secret>"
    },
    "instagram": {
        "profile": "<instagram username>",
        "access_token" :"<instagram access token>"
    },
    "pinterest": {
        "profile": "<pinterest username>",
        "access_token" :"<pinterest access token>"
    },
    "facebook": {
        "profile": "<facebook username>",
        "access_token" :"<facebook access token>"
    },
    "fivehundred":{
        "profile": "<500px username>",
        "access_token": "<500px consumer key>"
    }
    "flickr":{
        "access_token": "<flickr access token>",
        "user_id": "<flickr user id>",
        "album_id": "<album id>"
    }
    "rss": {
        "<RSS source id>"{
            "url": "<main URL of the site>",
            "rss_url": "<RSS URL>",
        }
    }
}

If you don’t want to fetch some social network (or don’t have an account), you can leave empty the dictionary for that social network.

Thus, you have to include the cache configuration:

# Cache stores information for 1 hour
LAST_SOCIAL_ACTIVITY_CACHE_DURATION_IN_HOURS = 1
LAST_SOCIAL_ACTIVITY_CACHE_DURATION_IN_MINUTES = None
LAST_SOCIAL_ACTIVITY_CACHE_DURATION_IN_SECONDS = None

By default, it caches the last posts/items in your profile in each social network for 1 hour if you want to change that, set None the fields you don’t want and set a number for the field you want.

Note the amount of duration is not additive so you only can define max lifetime for full hours, minutes and seconds.

Migrations

Don’t forget to execute migrations to create cache table for this application.

python manage.py migrate

Use

Template tags

Load this template tag in your templates:

{% load last_social_activity %}

For example:

{# Get the last 10 items of your RSS 'mysite' channel as defined in settings.py #}
{% last_rss_items 'mysite' 10 %}

{# Get the last 3 posts of your Facebook wall #}
{% last_facebook_posts 3 %}

{# Get the last 8 tweets #}
{% last_tweeets 8 %}

{# Get the last 12 images of Instagram #}
{% last_instagram_media 12 %}

{# Get the last 15 pins of Pinterest #}
{% last_pinterest_pins 15 %}

{# Get the last 25 photos of 500px #}
{% last_fivehundred_media 25 %}

{# Get the last 5 images of Flickr #}
{% last_flickr_media 5 %}

Customization

Customize each one of the templates creating a directory last_social_activity with one child with the name social_networks. That directory will contain a template for each social network (and your RSS channel if is configured):

  • facebook.html
  • instagram.html
  • pinterest.html
  • rss.html
  • twitter.html
  • fivehundred.html
  • flickr.html

Facebook

You have a list of post objects called posts with the following attributes:

  • id: id of this post
  • name: title of the post.
  • created_time: creation datetime of the post.
  • type: type of the post.
  • message: content of the post.
  • link: link to this facebook post.
  • permalink_url: link to this facebook post.

Take a look to the default template for an example.

Instagram

Data available comes from the member data of the following URL: https://api.instagram.com/v1/users/self/media/recent/?access_token=XXXX

Look to the default template.

Pinterest

Available fields are the ones returned by https://api.pinterest.com/v1/me/pins/?access_token=XXXX.

Look to the default template.

500px

Available fields are the ones returned by https://api.500px.com/v1/photos?consumer_key=XXXX.

Look to the default template.

Flickr

Available fields are the ones returned by https://api.flickr.com/services/rest/.

Look to the default template.

RSS

All RSS data is available as context in the template in the rss_items list.

You can access to all the attributes of each of your RSS items: name, description, pubdate, etc.

Look to the default template.

Twitter

Available context is a dict with the following structure:

{
    "tweets": [
        {
            "id": "<id of this tweet>",
            "text": "<content of the tweet>",
            "created_at": "<creation datetime of this tweet>"
        },
        # ...
    ],
    "profile_url": "<twitter_profile_url>",
    "username": "<twitter_username>"
}

Look to the default template.

Authors

Remove REMOVETHIS before emailing to one of the authors.

 
File Type Py Version Uploaded on Size
django-last-social-activity-0.2.1.tar.gz (md5) Source 2017-04-17 17KB