一个简单的django应用程序,可以获取您站点中的社交网络配置文件的最后一篇文章。
django-last-social-activit的Python项目详细描述
简介
此软件包允许您从收藏夹中获取最后状态 无需重新实现任何功能或 在浏览器端集成它们。
开发库是 https://github.com/intelligenia/django-last-social-activity。
这个软件的主要目的是拥有Django template tags 准备好在模板中加载最后一篇文章:
{# Load django-last-social-activity template tags #} {% load last_social_activity %} <divclass="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>
这个想法是个性化模板中的默认模板 你需要的文件夹。
安装
This package is in pypi所以 您可以使用pip命令轻松安装它:
pip install django-last-social-activity
或者从this GitHub repository安装 如果您想要主分支的最后功能:
# Master will allways be stable
pip install https://github.com//intelligenia/django-last-social-activity/archive/master.zip
依赖关系
这个包依赖于其他一些python包:
- 美化组4
- python dateutil
- python推特
- 请求
它们包含在这个包的要求中,所以您不会 手工安装。
配置
django settings.py
第一步是将应用程序last_social_activity包含到 您已安装的应用程序元组:
INSTALLED_APPS=(#..."last_social_activity"#...)
第二步是配置要包含的社交网络 在你的网站上。
将此词典放入settings.py文件中,填充。
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>",}}}
如果你不想获取一些社交网络(或者没有 帐户),您可以将该社交网络的字典留空。
因此,您必须包括缓存配置:
# Cache stores information for 1 hourLAST_SOCIAL_ACTIVITY_CACHE_DURATION_IN_HOURS=1LAST_SOCIAL_ACTIVITY_CACHE_DURATION_IN_MINUTES=NoneLAST_SOCIAL_ACTIVITY_CACHE_DURATION_IN_SECONDS=None
默认情况下,它在每个 一小时的社交网络如果你想改变它,不要设置 不需要的字段,并为所需字段设置一个数字。
注意,持续时间不是累加的,因此只能定义max 一个完整的小时,分钟和秒的生命。
迁移
不要忘记执行迁移以为此创建缓存表 申请。
python manage.py migrate
使用
定制
自定义每个模板创建目录 last_社交活动有一个名为 社交网络。该目录将包含每个 社交网络(以及您的RSS频道,如果已配置):
- facebook.html
- instagram.html
- pinterest.html
- rss.html
- twitter.html
- five100.html
- flickr.html
您有一个名为posts的post对象列表 属性:
- id:此帖子的id
- 姓名:职务。
- 创建时间:帖子的创建日期时间。
- 类型:职位类型。
- 留言:帖子内容。
- 链接:链接到这个facebook帖子。
- permalink_url:链接到这个facebook帖子。
看看default template 举个例子。
可用数据来自以下URL的成员data: https://api.instagram.com/v1/users/self/media/recent/?access_token=XXXX
推特
可用上下文是具有以下结构的dict:
{"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>"}