Package: item_synchronizer
Item SynchronizerDescriptionSynchronize items from two different sources in a bidirectional manner.This library aims to offer an abstract and versatile way tocreate,updateand/ordeleteitems to keep two "sources" in sync.These "items" may range from Calendar entries, TODO task lists, or whatever else
you want as long as the user registers the appropriate functions/methods to
convert from one said item to another.UsageTheSynchronizerclass requires the followingCallables to be given, for each
one of the sides. See the most up-to-date python typeshereInsertion callable: when called with the contents of an item it should create
and return the ID of the newly added item on the other sourceUpdate callable: update an item given by the item ID, using the (possibly
partial) new contents specified by ItemDeletion callable: Delete the item given by the specified IDConversion callable: convert an item from the format of one source to the
format of another.Item Gettercallable: Given the ID of an Item of one source return the
corresponding item on the other source.A_to_BbidictThis should be a bidict mapping IDs of A to the corresponding IDs of B and
vice-versa. Given this theitem_synchronizeris responsible for keeping
it up to date on insertion, update and deletion events. The contents of this
bidict should be persistent across the various runs, thus, consider
pickle-ing and unpickling its contents to diskAdditionallyitem_synchronizerneeds to know what items (their IDs) were
inserted, updated and deleted during the call to its main method,sync(). This
is dependent on your application at hand. You could either cache the items and
their content after each run and compare them with the latest state in the
current run. Or, the API of the calendar/task manager, etc. that you are using
may allow you to query the items that were modified/inserted/deleted since the
last run.ExamplesLet's say you want to bi-directionally synchronize your calendar events with
your TODO Task Manager tasks. This way, when you remove calendar event, the
correspoding task will be deleted, when you add a new task in your task manager,
a new calendar event will be created and when you update the task (e.g., change
its description or start time) the changes will reflect in the corresponding
calendar entry.Thus, you have the following and you want to sync theAandBitems.As described in the previous section,item_synchronizerrequires a set of
functions which it will call when it needs to insert, update or delete an item
from the corresponding side. It also requires anA_to_Bbidict persistent
across its runs with the item mappings between the two sides before the very
latest changes. Notice that,item_synchonizerwill be responsible for updating
entries in thisA_to_Bbidict, you do not need to do that manually. You only
need to make it persist across the different runs of theSynchronizer.sync()call (e.g., by pickle-ing and unpickle-ing it every time your application exits
and starts again.)Thus, this is the situation thatitem_synchronizerexpects at its first
run.After the first call tosync()here's the expected results. After this call
each event of one side will have a counterpart on the other side and that's also
going to be reflected in the providedA_to_Bbidict.Subsequent calls tosync()will pick up the changes and will insert any new
items from each side to the other side accordingly.Now let's say that item 2 was modified from side A, item 3 from side B and
item 21 was deleted from side A.In the subsequent call tosync(),item_synchronizerwill forward these
changes to the other side appropriately.If there was a conflict, e.g., an item removed from one side and updated from
the other, thenitem_synchronizersupports a series of resolution strategies
for handling such conflicts.InstallationAdd it as a dependency to either yourrequirements.txtor topyproject.toml[tool.poetry.dependencies]...item_synchronizer = "^1.0"...Or simply install it withpipif you want to use it locally:pip3installitem_synchronizerProjects using itProjects using this:Taskwarrior <-> Google Calendar Bidirectonal SynchronisationNotesCurrently IDs of items on either side should be ofstrtype.