Skip to content
forked from foxmask/django-th

Trigger Happy - micro Enterprise service bus (ESB) - a bridge between your internet services

Notifications You must be signed in to change notification settings

pouete/django-th

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travis Status Documentation status Latest version Supported Python versions License

Django Trigger Happy

Automatically share data between popular services you use on the web. And instead of giving your credentials to them, become the owner of yours !

For example a new RSS item is published, django-trigger-happy will be able to automatically create a note on your Evernote account or create a bookmark to your own Readability or Pocket account and so on

https://trigger-happy.eu/static/th_esb.png

Description

The goal of this project is to be independant from any other solution like IFTTT, CloudWork or others.

Thus you could host your own solution and manage your own triggers without depending any non-free solution.

With this project you can host triggers for you.

All you need is to have a hosting provider (or simply your own server ;) ) who permits to use a manager of tasks like "cron" and, of course Python.

Requirements

The latest should be installed with your operating system package manager, not from pip. On a Ubuntu system:

for celery

for evernote support

for pocket support

for twitter support

for readability support

for rss support

for redis support

for search engine

Installation

To get the project up and running, from your virtualenv, do:

git clone https://github.com/foxmask/django-th.git

To install the required modules, do:

pip install -r https://raw.githubusercontent.com/foxmask/django-th/master/requirements-all.txt

Parameters

As usual you will setup the database parameters.

Important parts are the settings of the available services :

settings.py

add the module django_th to the INSTALLED_APPS

INSTALLED_APPS = (
     ...
     'formtools',
     'django_js_reverse',
     'redisboard',
     'django_th',
     'th_rss',
     'th_pocket',
     'th_readability',
     'th_evernote',
     'th_twitter',
     'th_holidays',
     'haystack',  # mandatory  if you plan to use th_search
     'th_search', # then follow instructions from https://django-haystack.readthedocs.org/

 )
TH_SERVICES

TH_SERVICES is a list of the supported services

TH_SERVICES = (
    # comment the line to disable the service you dont want
    'th_rss.my_rss.ServiceRss',
    'th_pocket.my_pocket.ServicePocket',
    'th_evernote.my_evernote.ServiceEvernote',
    'th_readability.my_readability.ServiceReadability',
    'th_twitter.my_twitter.ServiceTwitter',
)
TH_EVERNOTE

TH_EVERNOTE is the settings you will need to be able to add/read data in/from Evernote.

To be able to use Evernote see official FAQ :

TH_EVERNOTE = {
    'sandbox': True, #set to False in production - to be able to use it with trigger happy of course ;)
    'consumer_key': 'abcdefghijklmnopqrstuvwxyz',
    'consumer_secret': 'abcdefghijklmnopqrstuvwxyz',
}
TH_POCKET

TH_POCKET is the settings you will need to be able to add/read data in/from Pocket.

To be able to use Pocket :

https://foxmask.info/public/trigger_happy/pocket_account_settings.png

  • then copy the "consumer key" of your application to the settings.py
TH_POCKET = {
    'consumer_key': 'abcdefghijklmnopqrstuvwxyz',
}
TH_READABILITY

TH_READABILITY is the settings you will need, to be able to add/read data in/from readability Service.

To be able to use readability :

https://foxmask.info/public/trigger_happy/readability_account_settings.png

  • copy the "keys & secret" of your application to the settings.py
TH_READABILITY = {
    'consumer_key': 'abcdefghijklmnopqrstuvwxyz',
    'consumer_secret': 'abcdefghijklmnopqrstuvwxyz',
}
TH_TWITTER

TH_TWITTER is the settings you will need to be able to add/read data in/from Twitter.

To be able to use Twitter:

  • you will need to create an account at https://apps.twitter.com/
  • then create an application
  • then on the Application Settings tab set the rights to "read and write permission"
  • then on Keys tab copy the infomartion and fill the settings.py with them

https://foxmask.info/public/trigger_happy/twitter_key_settings.png

TH_TWITTER = {
    'consumer_key': 'abcdefghijklmnopqrstuvwxyz',
    'consumer_secret': 'abcdefghijklmnopqrstuvwxyz',
}
CACHE

For each TriggerHappy component, define one cache like below

# Evernote Cache
'th_evernote':
{
    'TIMEOUT': 500,
    "BACKEND": "django_redis.cache.RedisCache",
    "LOCATION": "127.0.0.1:6379",
    "OPTIONS": {
        "DB": 1,
        "CLIENT_CLASS": "django_redis.client.DefaultClient",
    }
},
# Pocket Cache
'th_pocket':
{
    'TIMEOUT': 500,
    "BACKEND": "django_redis.cache.RedisCache",
    "LOCATION": "127.0.0.1:6379",
    "OPTIONS": {
        "DB": 2,
        "CLIENT_CLASS": "django_redis.client.DefaultClient",
    }
},
# RSS Cache
'th_rss':
{
    'TIMEOUT': 500,
    "BACKEND": "django_redis.cache.RedisCache",
    "LOCATION": "127.0.0.1:6379",
    "OPTIONS": {
        "DB": 3,
        "CLIENT_CLASS": "django_redis.client.DefaultClient",
    }
},
# Readability
'th_readability':
{
    'TIMEOUT': 500,
    "BACKEND": "django_redis.cache.RedisCache",
    "LOCATION": "127.0.0.1:6379",
    "OPTIONS": {
        "DB": 4,
        "CLIENT_CLASS": "django_redis.client.DefaultClient",
    }
},
# Twitter Cache
'th_twitter':
{
    'TIMEOUT': 500,
    "BACKEND": "django_redis.cache.RedisCache",
    "LOCATION": "127.0.0.1:6379",
    "OPTIONS": {
        "DB": 5,
        "CLIENT_CLASS": "django_redis.client.DefaultClient",
    }
},
CELERY

Celery will handle tasks itself to populate the cache from provider services and then exploit it to publish the data to the expected consumer services

  • From Settings

Define the broker then the scheduler

BROKER_URL = 'redis:https://localhost:6379/0'

CELERYBEAT_SCHEDULE = {
    'read-data': {
        'task': 'django_th.tasks.read_data',
        'schedule': crontab(minute='27,54'),
    },
    'publish-data': {
        'task': 'django_th.tasks.publish_data',
        'schedule': crontab(minute='59'),
    },
}
  • From SUPERVISORD
[program:django_th_worker]
user = foxmask
directory=/home/projects/trigger-happy/th
command=/home/projects/trigger-happy/bin/celery -A django_th worker --autoscale=10,3 -l info
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/projects/trigger-happy/logs/trigger-happy.log
stderr_logfile=/home/projects/trigger-happy/logs/trigger-happy-err.log

[program:django_th_beat]
user = foxmask
directory=/home/projects/trigger-happy/th
command=/home/projects/trigger-happy/bin/celery -A django_th beat -l info
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/projects/trigger-happy/logs/trigger-happy.log
stderr_logfile=/home/projects/trigger-happy/logs/trigger-happy-err.log

urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
     # Examples:
     # url(r'^$', 'th.views.home', name='home'),
     # url(r'^blog/', include('blog.urls')),

     url(r'^admin/', include(admin.site.urls)),
     url(r'', include('django_th.urls')),
)

Update the database

Once the settings is done, enter the following command to sync the database

if you start from scratch and dont have created a django application yet, you should do :

python manage.py syncdb

otherwise do :

python manage.py migrate

Starting the application

python manage.py runserver

Now that everything is in place, Celery will do our job in background in the meantime you will be able to manage your triggers from the front part

Setting up : Administration

Once the module is installed, go to the admin panel and activate the service you want.

Currently there are 4 services, Evernote, Pocket, RSS and Twitter.

https://foxmask.info/public/trigger_happy/th_admin_evernote_activated.png

https://foxmask.info/public/trigger_happy/th_admin_pocket_activated.png

https://foxmask.info/public/trigger_happy/th_admin_readability_activated.png

https://foxmask.info/public/trigger_happy/th_admin_rss_activated1.png

https://foxmask.info/public/trigger_happy/th_admin_twitter_activated.png

Once they are activated....

https://foxmask.info/public/trigger_happy/admin_service_list.png

... User can use them

Usage :

Activating services :

The user activates the service for their own need. If the service requires an external authentication, he will be redirected to the service which will ask him the authorization to acces the user's account. Once it's done, goes back to django-trigger-happy to finish and record the "auth token".

https://foxmask.info/public/trigger_happy/public_services_activated.png

Using the activated services :

a set of 3 pages will ask to the user information that will permit to trigger data from a service "provider" to a service "consummer".

For example :

  • page 1 : the user gives a RSS feed
  • page 2 : the user gives the name of the notebook where notes will be stored and a tag if he wants
  • page 3 : the user gives a description

Fire the Triggers by hands :

Here are the available management commands you can use by hand when you need to bypass the beat of Celery :

Available subcommands:

[django_th]
    fire_read_data     # will put date in cache
    fire_publish_data  # will read cache and publish data

To start handling the queue of triggers you/your users configured, just set those 2 management commands in a crontab or any other scheduler solution of your choice, if you dont want to use the beat of Celery

Also : Keep in mind to avoid to set a too short duration between 2 run to avoid to be blocked by the externals services (by their rate limitation) you/your users want to reach.

Complete Documentation

https://trigger-happy.readthedocs.org/

Blog posts :

You can find all details of all existing services of the blog : https://www.foxmask.info/tag/TriggerHappy

About

Trigger Happy - micro Enterprise service bus (ESB) - a bridge between your internet services

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 74.4%
  • HTML 25.0%
  • CSS 0.6%