Name | ckanext-twitter JSON |
Version |
2.2.9
JSON |
| download |
home_page | None |
Summary | A CKAN extension that enables users to post a tweet every time a dataset is created or updated. |
upload_time | 2024-05-14 10:47:14 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | GPL-3.0-or-later |
keywords |
ckan
data
twitter
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
<!--notices-start-->
> **Warning**
> ## This extension is now deprecated.
>
> Due to the API changes Twitter/X introduced in 2023, this extension no longer works and will not be fixed. There will not be any further releases, new features, or bugfixes.
<!--notices-end-->
<!--header-start-->
<img src="https://data.nhm.ac.uk/images/nhm_logo.svg" align="left" width="150px" height="100px" hspace="40"/>
# ckanext-twitter
[![Tests](https://img.shields.io/github/actions/workflow/status/NaturalHistoryMuseum/ckanext-twitter/main.yml?style=flat-square)](https://github.com/NaturalHistoryMuseum/ckanext-twitter/actions/workflows/main.yml)
[![Coveralls](https://img.shields.io/coveralls/github/NaturalHistoryMuseum/ckanext-twitter/main?style=flat-square)](https://coveralls.io/github/NaturalHistoryMuseum/ckanext-twitter)
[![CKAN](https://img.shields.io/badge/ckan-2.9.7-orange.svg?style=flat-square)](https://github.com/ckan/ckan)
[![Python](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-blue.svg?style=flat-square)](https://www.python.org/)
[![Docs](https://img.shields.io/readthedocs/ckanext-twitter?style=flat-square)](https://ckanext-twitter.readthedocs.io)
_A CKAN extension that enables users to post a tweet every time a dataset is created or updated._
<!--header-end-->
# Overview
<!--overview-start-->
This extension connects a CKAN instance to a Twitter account so that when a dataset is updated or created (i.e. the `after_update` hook is called), the user has the option to post a tweet about the activity.
<!--overview-end-->
# Installation
<!--installation-start-->
Path variables used below:
- `$INSTALL_FOLDER` (i.e. where CKAN is installed), e.g. `/usr/lib/ckan/default`
- `$CONFIG_FILE`, e.g. `/etc/ckan/default/development.ini`
## Installing from PyPI
```shell
pip install ckanext-twitter
```
## Installing from source
1. Clone the repository into the `src` folder:
```shell
cd $INSTALL_FOLDER/src
git clone https://github.com/NaturalHistoryMuseum/ckanext-twitter.git
```
2. Activate the virtual env:
```shell
. $INSTALL_FOLDER/bin/activate
```
3. Install via pip:
```shell
pip install $INSTALL_FOLDER/src/ckanext-twitter
```
### Installing in editable mode
Installing from a `pyproject.toml` in editable mode (i.e. `pip install -e`) requires `setuptools>=64`; however, CKAN 2.9 requires `setuptools==44.1.0`. See [our CKAN fork](https://github.com/NaturalHistoryMuseum/ckan) for a version of v2.9 that uses an updated setuptools if this functionality is something you need.
## Post-install setup
1. Add 'twitter' to the list of plugins in your `$CONFIG_FILE`:
```ini
ckan.plugins = ... twitter
```
2. Add a 'tweet' block to `read_base.html`:
```jinja2
{% block tweet %}
{{ super() }}
{% endblock %}
```
3. Optionally, override the styling of the block by creating an `ajax_snippets/edit_tweet.html` file.
<!--installation-end-->
# Configuration
<!--configuration-start-->
These are the options that can be specified in your .ini config file. The only _required_ options are the twitter credentials. Everything else has a sensible default set.
## **[REQUIRED]**
| Name | Description | Options |
|-----------------------------------|------------------------------|---------|
| `ckanext.twitter.consumer_key` | Your Twitter consumer key | |
| `ckanext.twitter.consumer_secret` | Your Twitter consumer secret | |
| `ckanext.twitter.token_key` | Your Twitter token key | |
| `ckanext.twitter.token_secret` | Your Twitter token secret | |
All of these can be obtained by creating a single-user app at [apps.twitter.com](https://apps.twitter.com). They can be found on the "keys and access tokens" tab when viewing your app.
## Tweet Templates
Tweets are generated using [Jinja2](http://jinja.pocoo.org) and use tokens derived from the package dictionary. See [Usage](#usage) for more detail.
| Name | Description | Default |
|---------------------------|--------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ckanext.twitter.new` | Template for tweets about new datasets | `New dataset: "{{ title }}" by {{ author }} ({%- if records != 0 -%} {{ records }} records {%- else -%} {{ resources }} resource {%- endif -%}).` |
| `ckanext.twitter.updated` | Template for tweets about updated datasets | `Updated dataset: "{{ title }}" by {{ author }} ({%- if records != 0 -%} {{ records }} records {%- else -%} {{ resources }} resource {%- endif -%}).` |
If your config is created dynamically using Jinja2, you will have to wrap any custom template in `{% raw %}{% endraw %}` tags and **add a newline after it**, e.g.:
```ini
ckanext.twitter.new = {% raw %}{{ title }} by {{ author }} ({{ records }} records) has just been published!{% endraw %}
ckanext.twitter.consumer_key = {{ twitter.consumer_key }}
ckanext.twitter...
```
## Other options
| Name | Description | Options | Default |
|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|-------------|---------|
| `ckanext.twitter.debug` | Is in debug mode; overrides global debug flag if specified | True, False | False |
| `ckanext.twitter.hours_between_tweets` | Number of hours between tweets about the _same dataset_ (to prevent spamming) | | 24 |
| `ckanext.twitter.disable_edit` | If true, users will not be able to edit the tweet about their dataset before it is posted (though they can still decide not to post it) | True, False | False |
<!--configuration-end-->
# Usage
<!--usage-start-->
## Tweet Templates
Token values for the tweet templates will come from a simplified package dictionary. In these, any collection values (i.e. lists and dictionaries) have been replaced with the number of items, the author list has been significantly shortened, and any long strings will be shortened to fit into the tweet character limit (currently set at 140).
For example, if the package dictionary is:
```python
{
'author': 'Dippy Diplodocus, Sophie Stegosaurus',
'author_email': None,
'dataset_category': ['Citizen Science'],
'doi': 'DOI_VALUE',
'license_title': 'Creative Commons Attribution',
'organization': {'description': '', 'name': 'nhm', 'is_organization': True, 'state': 'active'},
'resources': [
{'mimetype': 'image/jpeg', 'name': 'resource_1.jpg', 'format': 'JPEG'},
{'mimetype': 'image/jpeg', 'name': 'resource_2.jpg', 'format': 'JPEG'}
],
'title': 'Dataset Name'
}
```
Then the tokenised dictionary would be:
```python
{
'author': 'Diplodocus et al.', # just the surname of the first author
# author_email was None so it's excluded
'dataset_category': 1, # lists are counted
'doi': 'DOI_VALUE', # simple string values stay the same
'license_title': 'Creative Commons Attribution',
'organization': 4, # dicts are also counted
'resources': 2,
'title': 'Dataset Name'
}
```
And if you had defined the tweet template as:
```html+jinja
New dataset: "{{ title }}" by {{ author }} ({{ resources }} resources).
```
Your tweet would then read:
> New dataset: "Dataset Name" by Diplodocus et al. (2 resources)
<!--usage-end-->
# Testing
<!--testing-start-->
There is a Docker compose configuration available in this repository to make it easier to run tests. The ckan image uses the Dockerfile in the `docker/` folder.
To run the tests against ckan 2.9.x on Python3:
1. Build the required images:
```shell
docker-compose build
```
2. Then run the tests.
The root of the repository is mounted into the ckan container as a volume by the Docker compose
configuration, so you should only need to rebuild the ckan image if you change the extension's
dependencies.
```shell
docker-compose run ckan
```
Note that the tests shouldn't make any calls to Twitter's API and won't post any tweets.
<!--testing-end-->
Raw data
{
"_id": null,
"home_page": null,
"name": "ckanext-twitter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "CKAN, data, twitter",
"author": null,
"author_email": "Natural History Museum <data@nhm.ac.uk>",
"download_url": "https://files.pythonhosted.org/packages/25/9c/5e19f22e172ab3791f8bca8cc07affda90abea9a586695cabcd872442224/ckanext_twitter-2.2.9.tar.gz",
"platform": null,
"description": "<!--notices-start-->\n> **Warning**\n> ## This extension is now deprecated.\n>\n> Due to the API changes Twitter/X introduced in 2023, this extension no longer works and will not be fixed. There will not be any further releases, new features, or bugfixes.\n\n<!--notices-end-->\n\n<!--header-start-->\n<img src=\"https://data.nhm.ac.uk/images/nhm_logo.svg\" align=\"left\" width=\"150px\" height=\"100px\" hspace=\"40\"/>\n\n# ckanext-twitter\n\n[![Tests](https://img.shields.io/github/actions/workflow/status/NaturalHistoryMuseum/ckanext-twitter/main.yml?style=flat-square)](https://github.com/NaturalHistoryMuseum/ckanext-twitter/actions/workflows/main.yml)\n[![Coveralls](https://img.shields.io/coveralls/github/NaturalHistoryMuseum/ckanext-twitter/main?style=flat-square)](https://coveralls.io/github/NaturalHistoryMuseum/ckanext-twitter)\n[![CKAN](https://img.shields.io/badge/ckan-2.9.7-orange.svg?style=flat-square)](https://github.com/ckan/ckan)\n[![Python](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-blue.svg?style=flat-square)](https://www.python.org/)\n[![Docs](https://img.shields.io/readthedocs/ckanext-twitter?style=flat-square)](https://ckanext-twitter.readthedocs.io)\n\n_A CKAN extension that enables users to post a tweet every time a dataset is created or updated._\n\n<!--header-end-->\n\n# Overview\n\n<!--overview-start-->\nThis extension connects a CKAN instance to a Twitter account so that when a dataset is updated or created (i.e. the `after_update` hook is called), the user has the option to post a tweet about the activity.\n\n<!--overview-end-->\n\n# Installation\n\n<!--installation-start-->\nPath variables used below:\n- `$INSTALL_FOLDER` (i.e. where CKAN is installed), e.g. `/usr/lib/ckan/default`\n- `$CONFIG_FILE`, e.g. `/etc/ckan/default/development.ini`\n\n## Installing from PyPI\n\n```shell\npip install ckanext-twitter\n```\n\n## Installing from source\n\n1. Clone the repository into the `src` folder:\n ```shell\n cd $INSTALL_FOLDER/src\n git clone https://github.com/NaturalHistoryMuseum/ckanext-twitter.git\n ```\n\n2. Activate the virtual env:\n ```shell\n . $INSTALL_FOLDER/bin/activate\n ```\n\n3. Install via pip:\n ```shell\n pip install $INSTALL_FOLDER/src/ckanext-twitter\n ```\n\n### Installing in editable mode\n\nInstalling from a `pyproject.toml` in editable mode (i.e. `pip install -e`) requires `setuptools>=64`; however, CKAN 2.9 requires `setuptools==44.1.0`. See [our CKAN fork](https://github.com/NaturalHistoryMuseum/ckan) for a version of v2.9 that uses an updated setuptools if this functionality is something you need.\n\n## Post-install setup\n\n1. Add 'twitter' to the list of plugins in your `$CONFIG_FILE`:\n ```ini\n ckan.plugins = ... twitter\n ```\n\n2. Add a 'tweet' block to `read_base.html`:\n ```jinja2\n {% block tweet %}\n {{ super() }}\n {% endblock %}\n ```\n\n3. Optionally, override the styling of the block by creating an `ajax_snippets/edit_tweet.html` file.\n\n<!--installation-end-->\n\n# Configuration\n\n<!--configuration-start-->\nThese are the options that can be specified in your .ini config file. The only _required_ options are the twitter credentials. Everything else has a sensible default set.\n\n## **[REQUIRED]**\n\n| Name | Description | Options |\n|-----------------------------------|------------------------------|---------|\n| `ckanext.twitter.consumer_key` | Your Twitter consumer key | |\n| `ckanext.twitter.consumer_secret` | Your Twitter consumer secret | |\n| `ckanext.twitter.token_key` | Your Twitter token key | |\n| `ckanext.twitter.token_secret` | Your Twitter token secret | |\n\nAll of these can be obtained by creating a single-user app at [apps.twitter.com](https://apps.twitter.com). They can be found on the \"keys and access tokens\" tab when viewing your app.\n\n## Tweet Templates\n\nTweets are generated using [Jinja2](http://jinja.pocoo.org) and use tokens derived from the package dictionary. See [Usage](#usage) for more detail.\n\n| Name | Description | Default |\n|---------------------------|--------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ckanext.twitter.new` | Template for tweets about new datasets | `New dataset: \"{{ title }}\" by {{ author }} ({%- if records != 0 -%} {{ records }} records {%- else -%} {{ resources }} resource {%- endif -%}).` |\n| `ckanext.twitter.updated` | Template for tweets about updated datasets | `Updated dataset: \"{{ title }}\" by {{ author }} ({%- if records != 0 -%} {{ records }} records {%- else -%} {{ resources }} resource {%- endif -%}).` |\n\nIf your config is created dynamically using Jinja2, you will have to wrap any custom template in `{% raw %}{% endraw %}` tags and **add a newline after it**, e.g.:\n```ini\nckanext.twitter.new = {% raw %}{{ title }} by {{ author }} ({{ records }} records) has just been published!{% endraw %}\n\nckanext.twitter.consumer_key = {{ twitter.consumer_key }}\nckanext.twitter...\n```\n\n## Other options\n\n| Name | Description | Options | Default |\n|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|-------------|---------|\n| `ckanext.twitter.debug` | Is in debug mode; overrides global debug flag if specified | True, False | False |\n| `ckanext.twitter.hours_between_tweets` | Number of hours between tweets about the _same dataset_ (to prevent spamming) | | 24 |\n| `ckanext.twitter.disable_edit` | If true, users will not be able to edit the tweet about their dataset before it is posted (though they can still decide not to post it) | True, False | False |\n\n<!--configuration-end-->\n\n# Usage\n\n<!--usage-start-->\n## Tweet Templates\n\nToken values for the tweet templates will come from a simplified package dictionary. In these, any collection values (i.e. lists and dictionaries) have been replaced with the number of items, the author list has been significantly shortened, and any long strings will be shortened to fit into the tweet character limit (currently set at 140).\n\nFor example, if the package dictionary is:\n```python\n{\n 'author': 'Dippy Diplodocus, Sophie Stegosaurus',\n 'author_email': None,\n 'dataset_category': ['Citizen Science'],\n 'doi': 'DOI_VALUE',\n 'license_title': 'Creative Commons Attribution',\n 'organization': {'description': '', 'name': 'nhm', 'is_organization': True, 'state': 'active'},\n 'resources': [\n {'mimetype': 'image/jpeg', 'name': 'resource_1.jpg', 'format': 'JPEG'},\n {'mimetype': 'image/jpeg', 'name': 'resource_2.jpg', 'format': 'JPEG'}\n ],\n 'title': 'Dataset Name'\n}\n```\n\nThen the tokenised dictionary would be:\n\n```python\n{\n 'author': 'Diplodocus et al.', # just the surname of the first author\n # author_email was None so it's excluded\n 'dataset_category': 1, # lists are counted\n 'doi': 'DOI_VALUE', # simple string values stay the same\n 'license_title': 'Creative Commons Attribution',\n 'organization': 4, # dicts are also counted\n 'resources': 2,\n 'title': 'Dataset Name'\n}\n```\n\nAnd if you had defined the tweet template as:\n```html+jinja\nNew dataset: \"{{ title }}\" by {{ author }} ({{ resources }} resources).\n```\n\nYour tweet would then read:\n\n> New dataset: \"Dataset Name\" by Diplodocus et al. (2 resources)\n\n<!--usage-end-->\n\n# Testing\n\n<!--testing-start-->\nThere is a Docker compose configuration available in this repository to make it easier to run tests. The ckan image uses the Dockerfile in the `docker/` folder.\n\nTo run the tests against ckan 2.9.x on Python3:\n\n1. Build the required images:\n ```shell\n docker-compose build\n ```\n\n2. Then run the tests.\n The root of the repository is mounted into the ckan container as a volume by the Docker compose\n configuration, so you should only need to rebuild the ckan image if you change the extension's\n dependencies.\n ```shell\n docker-compose run ckan\n ```\n\nNote that the tests shouldn't make any calls to Twitter's API and won't post any tweets.\n\n<!--testing-end-->\n",
"bugtrack_url": null,
"license": "GPL-3.0-or-later",
"summary": "A CKAN extension that enables users to post a tweet every time a dataset is created or updated.",
"version": "2.2.9",
"project_urls": {
"changelog": "https://github.com/NaturalHistoryMuseum/ckanext-twitter/blob/main/CHANGELOG.md",
"repository": "https://github.com/NaturalHistoryMuseum/ckanext-twitter"
},
"split_keywords": [
"ckan",
" data",
" twitter"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2ecfd51ccfde91bd7ec7e6022b456a047560cbc3125303ec50310ac6ac098048",
"md5": "79654fc3ca67883570e7a81a09f7cec0",
"sha256": "cbe52bc9ab79c844bbd8608355152596977a903505d44f511c7c6e5a7de66a2d"
},
"downloads": -1,
"filename": "ckanext_twitter-2.2.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "79654fc3ca67883570e7a81a09f7cec0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 30536,
"upload_time": "2024-05-14T10:47:13",
"upload_time_iso_8601": "2024-05-14T10:47:13.696148Z",
"url": "https://files.pythonhosted.org/packages/2e/cf/d51ccfde91bd7ec7e6022b456a047560cbc3125303ec50310ac6ac098048/ckanext_twitter-2.2.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "259c5e19f22e172ab3791f8bca8cc07affda90abea9a586695cabcd872442224",
"md5": "ef3b138b16a6dd85d4b85ad989a09621",
"sha256": "f86c3ae93bdfb78504bc2759fa753c0fed1835f3ac42d98e5889e6e5a70fb317"
},
"downloads": -1,
"filename": "ckanext_twitter-2.2.9.tar.gz",
"has_sig": false,
"md5_digest": "ef3b138b16a6dd85d4b85ad989a09621",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 32331,
"upload_time": "2024-05-14T10:47:14",
"upload_time_iso_8601": "2024-05-14T10:47:14.975449Z",
"url": "https://files.pythonhosted.org/packages/25/9c/5e19f22e172ab3791f8bca8cc07affda90abea9a586695cabcd872442224/ckanext_twitter-2.2.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-14 10:47:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NaturalHistoryMuseum",
"github_project": "ckanext-twitter",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "ckanext-twitter"
}