Name: ckanext-twitter
Owner: Natural History Museum
Description: A CKAN plugin to post tweets when datasets are created and updated.
Created: 2017-12-08 15:52:12.0
Updated: 2017-12-08 16:05:12.0
Pushed: 2018-04-04 12:31:02.0
Homepage: null
Size: 57
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Sends a tweet every time a dataset is created or updated in the database.
Clone the repository into the virtual env's src
folder:
usr/lib/ckan/default/src/
clone https://github.com/NaturalHistoryMuseum/ckanext-twitter.git
Activate the virtual env:
sr/lib/ckan/default/bin/activate
Run setup.py:
usr/lib/ckan/default/src/ckanext-twitter
on setup.py develop
Add 'twitter' to the list of plugins in your config file:
.plugins = ... twitter
Install the requirements from requirements.txt:
usr/lib/ckan/default/src/ckanext-twitter
install -r requirements.txt
There are a number of 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.
ext.twitter.consumer_key = YOUR-CONSUMER-KEY
ext.twitter.consumer_secret = YOUR-CONSUMER-SECRET
ext.twitter.token_key = YOUR-TOKEN-KEY
ext.twitter.token_secret = YOUR-TOKEN-SECRET
All of these can be obtained by creating a single-user app at apps.twitter.com. They can be found on the “keys and access tokens” tab when viewing your app.
Tweets are generated using Jinja2 and a set of parsers to extract/shorten common pieces of information from the package dictionary. These templates can be overwritten in the config.
The default for ckanext.twitter.new
(the option for the 'new dataset' tweet template) is:
dataset: "{{ title }}" by {{ author }} ({%- if records != 0 -%} {{ records }} records {%- else -%} {{ resources }} resource {%- endif -%}).
And the default for ckanext.twitter.updated
is:
ted 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.:
ext.twitter.new = {% raw %}{{ title }} by {{ author }} ({{ records }} records) has just been published!{% endraw %}
ext.twitter.consumer_key = {{ twitter.consumer_key }}
ext.twitter.consumer_secret = {{ twitter.consumer_secret }}
ext.twitter.token_key = {{ twitter.token_key }}
ext.twitter.token_secret = {{ twitter.token_secret }}
Token values will come from a simplified package dictionary where 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). Some example keys:
r_org
ate
tags
data_created
data_modified
or
resources
rds
en
s
e
nization
Name|Description|Default
–|—|–
ckanext.twitter.debug
|Is in debug mode; overrides global debug flag if specified|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)|False
None of the tests should actually post any tweets to Twitter.
They will test authentication, but nothing should be posted.
To run the tests, use nosetests inside your virtualenv. The --nocapture
flag will allow you to see the tweets being printed to the console instead of posted to twitter (as the tests are mostly run in debug mode) but will also print a lot of statements about database manipulation.
tests --ckan --with-pylons=/path/to/your/test.ini --where=/path/to/your/install/directory/ckanext-twitter --nologcapture --nocapture