GithubHelp home page GithubHelp logo

isabella232 / ckanext-twitter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from opengov-opendata/ckanext-twitter

0.0 0.0 0.0 149 KB

A CKAN plugin to post tweets when datasets are created and updated.

License: GNU General Public License v3.0

JavaScript 5.24% Python 91.88% HTML 2.88%

ckanext-twitter's Introduction

ckanext-twitter

Sends a tweet every time a dataset is created or updated in the database.

Setup

  1. Clone the repository into the virtual env's src folder:
cd /usr/lib/ckan/default/src/
git clone https://github.com/NaturalHistoryMuseum/ckanext-twitter.git
  1. Activate the virtual env:
. /usr/lib/ckan/default/bin/activate
  1. Run setup.py:
cd /usr/lib/ckan/default/src/ckanext-twitter
python setup.py develop
  1. Add 'twitter' to the list of plugins in your config file:
ckan.plugins = ... twitter
  1. Install the requirements from requirements.txt:
cd /usr/lib/ckan/default/src/ckanext-twitter
pip install -r requirements.txt

Configuration

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.

Twitter Credentials [REQUIRED]

ckanext.twitter.consumer_key = YOUR-CONSUMER-KEY
ckanext.twitter.consumer_secret = YOUR-CONSUMER-SECRET
ckanext.twitter.token_key = YOUR-TOKEN-KEY
ckanext.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.

Tweet Templates

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:

New dataset: "{{ title }}" by {{ author }} ({%- if records != 0 -%} {{ records }} records {%- else -%} {{ resources }} resource {%- endif -%}).

And the default for ckanext.twitter.updated is:

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.:

ckanext.twitter.new = {% raw %}{{ title }} by {{ author }} ({{ records }} records) has just been published!{% endraw %}

ckanext.twitter.consumer_key = {{ twitter.consumer_key }}
ckanext.twitter.consumer_secret = {{ twitter.consumer_secret }}
ckanext.twitter.token_key = {{ twitter.token_key }}
ckanext.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:

owner_org
private
num_tags
id
metadata_created
metadata_modified
author
type
num_resources
records
name
isopen
notes
title
organization

Other options

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

Testing

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.

nosetests --ckan --with-pylons=/path/to/your/test.ini --where=/path/to/your/install/directory/ckanext-twitter --nologcapture --nocapture

ckanext-twitter's People

Contributors

alycejenni avatar jrdh avatar jguo144 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.