一个简单的django应用程序,可以获取您站点中的社交网络配置文件的最后一篇文章。

django-last-social-activit的Python项目详细描述


Django上次社交活动

一个简单的Django应用程序 在你的站点中获取你的社交网络配置文件的最后一篇文章。

简介

此软件包允许您从收藏夹中获取最后状态 无需重新实现任何功能或 在浏览器端集成它们。

开发库是 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

使用

模板标签

在模板中加载此模板标记:

{% load last_social_activity %}

例如:

{# 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 %}

定制

自定义每个模板创建目录 last_社交活动有一个名为 社交网络。该目录将包含每个 社交网络(以及您的RSS频道,如果已配置):

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

Facebook

您有一个名为posts的post对象列表 属性:

  • id:此帖子的id
  • 姓名:职务。
  • 创建时间:帖子的创建日期时间。
  • 类型:职位类型。
  • 留言:帖子内容。
  • 链接:链接到这个facebook帖子。
  • permalink_url:链接到这个facebook帖子。

看看default template 举个例子。

Instagram

可用数据来自以下URL的成员datahttps://api.instagram.com/v1/users/self/media/recent/?access_token=XXXX

看看default template

rss

所有RSS数据都可用作为模板中的上下文 rss\u项列表。

您可以访问每个rss项目的所有属性:name, 说明、发布日期等

看看default template

推特

可用上下文是具有以下结构的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>"}

看看default template

作者

在给其中一个作者发送电子邮件之前删除removethis。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
无法使用windows x86上的Java验证在linux x64上签名的数字签名   java Firebase通过键从子级检索数据   Java缓存网络文件   java独立jdbcpool实现内存泄漏   java为什么MVN在成功构建时返回1?   java maven正在抛出BoundsException数组   Java:是否可以有“嵌套”映射方法(Java.util.stream)?   java无法使用GSON解析JSON文件   java Spring Groovy集成   java使用SAX解析器,需要所有xml元素(在特定元素下)作为字符串   java列出内容提供商Android 3.1中的内容   java如何使用带有spring api的JPA查询进行软删除?   java隐藏我的socket构造函数以隐藏IP和端口   Java将(JEP359)记录为Spring控制器请求和响应DTO   java在数组中循环时忽略空值   RESTAPI端点的java发现模式   java HTTPs在jmeter中发布带有头的请求测试,并将测试结果保存在mongodb中,并在grafana中显示