Plugin API

BaseSource

class livebridge.base.BaseSource(*, config={}, **kwargs)

Bases: object

Base class for sources.

type = Defines source type
mode = Defines source mode
__init__(*, config={}, **kwargs)[source]

Base constructor for sources.

Parameters:config – Configuration passed from the control file.
_db

Database client for accessing storage.

Returns:livebridge.storages.base.BaseStorage
filter_new_posts(source_id, post_ids)[source]

Filters ist of post_id for new ones.

Parameters:
  • source_id – id of the source
  • post_ids – list of post ids
Returns:

list of unknown post ids.

get_last_updated(source_id)[source]

Returns latest update-timestamp from storage for source.

Parameters:source_id – id of the source (source_id, ticker_id, blog_id pp)
Returns:datetime.datetime object of latest update datetime in db.
mode = ''
type = ''
class livebridge.base.PollingSource(*, config={}, **kwargs)[source]

Bases: livebridge.base.BaseSource

Base class for sources which are getting polled. Any custom adapter source, which should get polled, has to be inherited from this base class.

mode = 'polling'
poll()[source]

Method has to be implemented by the concrete inherited source class.

poll() gets called by the interval defined by environment var POLLING_INTERVALL.

The inheriting class has to implement the actual poll request for the source in this method.

Returns:list of new posts
stop()[source]

Method can be implemented by the concrete inherited source class.

By implementing this method, the source class is able to handle the shutdown event explicitly.

class livebridge.base.StreamingSource(*, config={}, **kwargs)[source]

Bases: livebridge.base.BaseSource

Base class for streaming sources. Any custom adapter source, which is using a websocket, SSE or any other stream as source has to be inherited from this base class.

listen(callback)[source]

Method has to be implemented by the concrete inherited source class.

A websocket connection has to be opened and given callback method has to be called with the new post as argument.

Parameters:callback – Callback method which has to be called with list of new posts.
Returns:True
mode = 'streaming'
stop()[source]

Method has to be implemented by the concrete inherited source class.

By calling this method, the websocket-connection has to be stopped.

Returns:True

BasePost

class livebridge.base.BasePost(data, *, content='', images=[])

Bases: object

Base class for posts.

Every concrete implementation of this base class have to implement the poperties defined here. This is needed, so the specific targets do not have to differentiate by the post type, but rather have a unified way to access common properties from the resource, regardless of their source.

source = Defines source type
__init__(data, *, content='', images=[])[source]

Base constructor for targets.

Parameters:
  • data
    • dictionary of source post data
  • content
    • string of convertered post content, optional
  • images
    • list of iage_paths, optional
created

Returns created datetime of the resource, has to be a datetime.datetime object.

get_action()[source]

Returns type of action which has to be handled by the target. Can be either create, update, delete or ignore.

get_existing()[source]

Returns existing resource at target.

Returns:
  • dict of resource
id

Returns the id of the resource at its source.

is_deleted

Returns boolean if resource is deleted or not.

is_draft

Returns boolean if resource is in drafted state.

is_known

Returns boolean if resource is already known to livebridge.

is_sticky

Returns boolean if resource is sticky or not.

is_submitted

Returns boolean if resource is in submitted state.

is_update

Returns boolean if resource is updated or not.

set_existing(existing)[source]

Takes existing doc at target.

Parameters:existing
  • dict, resource doc at target.
source = ''
source_id

Returns the id of the source. For example the id of the blog polled.

target_doc

Returns resource doc as at the target, when the posting was already created at the target. This property normally contains the target_doc data from the livebrigde storage item, saved in a syndication earlier.

Returns:dict
target_id

Returns the id the target, to which this post has to be syndicated.

Returns:string
updated

Returns updated datetime of the resource, has to be a datetime.datetime object.

BaseConverter

class livebridge.base.BaseConverter

Bases: object

Base class for converters.

Concrete implementations have to implement public convert() method.

source = Specifies the type of the source post
target = Specifies the target type of the conversion
convert(post)[source]

Convert incoming content of the incoming raw source post to a string suitable to the target as content.

Parameters:post – raw source post
Returns:livebridge.base.ConversionResult - result of the conversion.
remove_images(images)[source]
source = ''
target = ''

ConversionResult

class livebridge.base.ConversionResult(content, images=None)[source]

Bases: object

Result object for conversions.

Parameters:
  • content – content result of conversion
  • images – list of local file paths of downloaded images, optional

BaseTarget

class livebridge.base.BaseTarget(*, config={}, **kwargs)

Bases: object

Base class for targets.

Every concrete implementation of a target, requires to implement following methods:

If a method above is not needed, for example when no update is possible at the target, use livebridge.posts.base.BasePost.get_action() to ignore this action.

type = Defines target type
__init__(*, config={}, **kwargs)[source]

Base constructor for targets.

Parameters:config – Configuration passed from the control file.
delete_item(post)[source]

Deletes an existing resource at target.

Parameters:post
  • Object of type livebridge.posts.base.BasePost
Returns:
handle_extras(post)[source]

Handle extra actions, for example set resource to sticky at the target. Return None if method is unneeded.

Parameters:post
  • Object of type livebridge.posts.base.BasePost
Returns:
handle_post(post)[source]
post_item(post)[source]

Creates new resource at target.

Parameters:post
  • Object of type livebridge.posts.base.BasePost
Returns:
type = 'base'
update_item(post)[source]

Updates existing resource resource at target.

Parameters:post
  • Object of type livebridge.posts.base.BasePost
Returns:

TargetResponse

class livebridge.base.TargetResponse(**kwargs)[source]

Bases: collections.UserDict

Data container for returning the resource data from a service, awaits dictionary.

Data returned from a BaseTarget derived target type has to be a TargetResponse.

clear() → None. Remove all items from D.
copy()
classmethod fromkeys(iterable, value=None)
get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → an object providing a view on D's values

InvalidTargetResource

exception livebridge.base.InvalidTargetResource[source]

This exception ca be raised, when a known resource target is invalid. This exception will prevent a retry of a failed action.

BaseStorage

class livebridge.storages.base.BaseStorage[source]

Bases: object

Base class for storage clients.

Every concrete implementation of a storage class, requires to implement following methods:

db

Property holds underlying database client.

delete_post(target_id, post_id)[source]

Deletes single post from storage.

Parameters:
  • target_id – id of the target
  • post_id – id of post to delete
get_control()[source]

Method for retrieving of control data form storage.

Returns:
  • dictionary
get_known_posts(source_id, post_ids)[source]

Return a list of known post_id of a source for a given list of post ids.

Parameters:
  • source_id – id of the source
  • post_ids – list of post ids
Returns:

  • list of dictionaries.

get_last_updated(source_id)[source]

Returns latest updated-timestamp of source from storage.

Parameters:source_id – id of the source
get_post(target_id, post_id)[source]

Returns single post from storage.

Parameters:
  • target_id – id of the target
  • post_id – id of post
insert_post(**kwargs)[source]

Insert single post into storage.

save_control(data)[source]

Method for saving control data in storage.

Parameters:data – control_data
Returns:
  • boolean
setup()[source]

Method for setting up storage, creating table pp.

shutdown()[source]

Method for closing db client, gets called right before closing the event loop. Needed by DynamoDB client

update_post(**kwargs)[source]

Updates single post in storage.