{ "info": { "author": "nevimov", "author_email": "nevimov@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.10", "Framework :: Django :: 1.7", "Framework :: Django :: 1.8", "Framework :: Django :: 1.9", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Internet :: WWW/HTTP" ], "description": "========================\ndjango-facebook-insights\n========================\n\nCollect and store `Facebook Insights`_ metrics using Django models.\n\nThis app provides a flexible abstract model with method `fetch()`. It gets all\nrequired metrics with a single `batch request`_ to Graph API and puts them into\nyour child model's fields.\n\n**Requirements**:\n\n* Django 1.7 to 1.10 on Python 2.7\n* Django 1.8 to 1.10 on Python 3.4 and 3.5\n* facebook-sdk 1.0.0+\n\n.. contents::\n :depth: 1\n :backlinks: top\n\n\nInstallation\n------------\n\nInstall the app with pip::\n\n $ pip install django-facebook-insights\n\nAdd `'facebook_insights'` to your `INSTALLED_APPS` setting::\n\n INSTALLED_APPS = [\n ...\n 'facebook_insights',\n ]\n\nFinally, provide a valid access token with the 'read_insights' permission using\nsetting `FACEBOOK_INSIGHTS_ACCESS_TOKEN`.\n\n\nUsage example\n-------------\n\nIn the simplest case, all you need to do is to write code similar to the\none below::\n\n from django.db import models\n from facebook_insights.models import Insights\n\n\n # Inherit from the abstract 'Insights' model\n class PostInsights(Insights):\n # List metrics you're intrested in\n METRICS = [\n 'post_impressions',\n 'post_impressions_unique',\n 'post_stories',\n 'post_stories_by_action_type',\n ]\n # Define field 'graph_id' to hold the Facebook ids of objects\n graph_id = models.CharField(max_length=100)\n # Define fields to store the metrics\n impressions = models.PositiveIntegerField()\n impressions_unique = models.PositiveIntegerField()\n stories = models.PositiveIntegerField()\n stories_by_action_type = models.CharField(max_length=100)\n\n.. note::\n If you want to use a different name for the graph id field, change\n attribute GRAPH_ID_FIELD to the desired value.\n\nNow, you can instantiate the model and call fetch() to get the metrics from\nFacebook's servers::\n\n >>> post_insights = PostInsights(graph_id=your_post_id)\n >>> post_insights.fetch()\n >>> post_insights.impressions\n 1000\n >>> post_insights.impressions_unique\n 200\n >>> post_insights.stories\n 100\n >>> post_insights.stories_by_action_type\n '{\"like\": 40, \"share\": 30, \"comment\": 30}'\n\n\nMapping metrics to fields\n-------------------------\n\nTo figure out which metrics belong to which fields, the app uses the following\nsimple algorithm:\n\n* Take the metric name as the base name.\n\n* Remove the object type prefix (``'post_', 'page_' or 'domain_'``),\n if attribute REMOVE_PREFIX is set to True (the default).\n The prefix is removed, so we can, for instance, access the\n 'post_impressions' metric as `post_insights.impressions` instead of\n `post_insights.post_impressions`.\n\n.. note::\n\n The full list of *metrics* with their *periods* can be found in Graph API\n Reference on `Object Insights`_.\n\nIf you want to use a more complex algorithm, you need to override the\n`get_field_name()` method.\n\n\nExtracting field values\n-----------------------\n\nValues associated with page metrics are quite complex. They are available for\nseveral periods (e.g. day, week, 28 days) and include data for 3 consecutive\ndays. By contrast, values of most of post metrics are available only for one\nperiod (lifetime) and represent the current state of things.\n\nThe extraction of metric values is the responsibility of the\n`get_field_value()` method. The default implementation works as follows:\n\n* If a metric has several periods, return the dictionary of mappings between\n the periods and the last available values for these periods serialized into\n JSON, for example, `'{\"day\": 10, \"week\": 70, \"days_28\": 300\"}'`. The data\n for previous days are discarded.\n* If a metric is provided only for a single period, then simply return the\n value (serialize, if it's not a number).\n\nFeel free to override the method, if you want something else.\n\n\nGetting object_id from a related object\n---------------------------------------\n\nIn case you already have a model representing a Facebook page or post, you will\nlikely want to get the graph ids from instances of this model. To do this,\nall you need is to set attribute RELATED_OBJECT_FIELD to the name of the field\nreferencing the related object::\n\n class Page(models.Model):\n graph_id = models.CharField(\n max_length=100,\n primary_key=True,\n help_text=\"The page's ID on Facebook\",\n )\n\n\n class PageInsights(Insights):\n RELATED_OBJECT_FIELD = 'page'\n METRICS = [ ... ]\n page = models.OneToOneField(\n Page,\n primary_key=True,\n related_name='insights',\n )\n ...\n\n\nReporting bugs\n--------------\n\nIf you've found a bug:\n\n* Check to see if there's an existing issue/pull request for the bug.\n\n | PR: https://github.com/nevimov/django-facebook-insights/pulls\n | Issues: https://github.com/nevimov/django-facebook-insights/issues\n\n* If there isn't one, file an issue. A bug report should include:\n\n * a description of the problem\n * instructions on how to recreate the bug\n * versions of your Python interpreter and Django\n\n\nContributing code\n-----------------\n\n* Fork the project on GitHub to your account.\n\n* Clone the repository::\n\n $ git clone https://github.com/nevimov/django-facebook-insights\n\n* Setup a virtual environment::\n\n $ virtualenv venv\n $ source venv/bin/activate\n $ pip install -U pip\n $ pip install django\n $ pip install -r requirements.txt\n\n* In directory 'tests' create a file named 'secret.py'. In this file, set\n the `FACEBOOK_INSIGHTS_ACCESS_TOKEN` setting'. Alternatively, define an\n environment variable with the same name.\n\n* Run tests to ensure everything is OK::\n\n $ python runtests.py\n\n You can use *-h* or *--help* to see options available to the script.\n\n* Create a topic branch and commit your changes there.\n\n* Push the branch up to GitHub.\n\n* Create a new pull request.\n\n\n.. _Object Insights:\n.. _Facebook Insights: https://developers.facebook.com/docs/graph-api/reference/v2.8/insights\n.. _batch request: https://developers.facebook.com/docs/graph-api/making-multiple-requests", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nevimov/django-facebook-insights", "keywords": "django facebook insights metrics stats statistics", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-facebook-insights", "package_url": "https://pypi.org/project/django-facebook-insights/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-facebook-insights/", "project_urls": { "Homepage": "https://github.com/nevimov/django-facebook-insights" }, "release_url": "https://pypi.org/project/django-facebook-insights/0.1.0/", "requires_dist": [ "facebook-sdk (>=1,<3)" ], "requires_python": "", "summary": "Collect and store Facebook Insights metrics using Django models.", "version": "0.1.0" }, "last_serial": 2473916, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "268cf4aab3b02bac6d50946cd9c0f7ee", "sha256": "d2b665a05f6ba211c44d7e27e506aea48a160acc13316f73530064761cfc4a2d" }, "downloads": -1, "filename": "django_facebook_insights-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "268cf4aab3b02bac6d50946cd9c0f7ee", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12469, "upload_time": "2016-11-21T12:09:14", "url": "https://files.pythonhosted.org/packages/7c/b9/5484c539fdb4fe6ecd5bfc53958bb3c0f365da8790005e862f8cc882a40a/django_facebook_insights-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "189463e9a3f5a29ab40f6ce81e6e9497", "sha256": "0bd9b6dd037e89cda6fd6c2141c5357903b3f0889a62937316f138577a7b5552" }, "downloads": -1, "filename": "django-facebook-insights-0.1.0.tar.gz", "has_sig": false, "md5_digest": "189463e9a3f5a29ab40f6ce81e6e9497", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8937, "upload_time": "2016-11-21T12:09:17", "url": "https://files.pythonhosted.org/packages/13/98/a28745e0c364c1405727de6278f582ed153f420795d81219091e39fba685/django-facebook-insights-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "268cf4aab3b02bac6d50946cd9c0f7ee", "sha256": "d2b665a05f6ba211c44d7e27e506aea48a160acc13316f73530064761cfc4a2d" }, "downloads": -1, "filename": "django_facebook_insights-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "268cf4aab3b02bac6d50946cd9c0f7ee", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12469, "upload_time": "2016-11-21T12:09:14", "url": "https://files.pythonhosted.org/packages/7c/b9/5484c539fdb4fe6ecd5bfc53958bb3c0f365da8790005e862f8cc882a40a/django_facebook_insights-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "189463e9a3f5a29ab40f6ce81e6e9497", "sha256": "0bd9b6dd037e89cda6fd6c2141c5357903b3f0889a62937316f138577a7b5552" }, "downloads": -1, "filename": "django-facebook-insights-0.1.0.tar.gz", "has_sig": false, "md5_digest": "189463e9a3f5a29ab40f6ce81e6e9497", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8937, "upload_time": "2016-11-21T12:09:17", "url": "https://files.pythonhosted.org/packages/13/98/a28745e0c364c1405727de6278f582ed153f420795d81219091e39fba685/django-facebook-insights-0.1.0.tar.gz" } ] }