Introduction
This section is a walkthrough of the contents of the module, intended to explain how mosromgr works and introduce the concepts.
MOS Types
The MOS Types section of the module provides a collection of classes for dealing with individual MOS messages. The classes provide easy access to some of the elements within a MOS file, such as a list of stories within a running order, the transmission time of a programme, or its duration.
For example, you can load a running order from a roCreate
file, print the RO
Slug and access some details:
>>> from mosromgr.mostypes import RunningOrder
>>> ro = RunningOrder.from_file('123456-roCreate.mos.xml')
>>> ro.ro_slug
'22:45 NEWSNIGHT 54D CORE Thu, 08.04.2021'
>>> ro.message_id
123456
>>> ro.start_time
datetime.datetime(2021, 4, 8, 21, 46, 30)
>>> ro.duration
970.0
>>> len(ro.stories)
10
In the case of MOS messages which contain a change to a running order, the
relevant details are exposed, for example a
StoryInsert
includes access to the
source_stories
and
target_story
.
When dealing with merging MosFile
objects, this is
done by “adding” each file to the RunningOrder
object by using the +
operator:
>>> from mosromgr.mostypes import RunningOrder, StoryInsert
>>> ro = RunningOrder.from_file('123456-roCreate.mos.xml')
>>> ss = StoryInsert.from_file('123457-roStoryInsert.mos.xml')
>>> len(ro.stories)
10
>>> ro += ss
>>> len(ro.stories)
11
MOS Elements
The MOS Elements part of the module provides a collection of classes
used to provide easy access to certain elements within a
MosFile
object, such as a list of stories within a
running order, and the items within a story:
from mosromgr.mostypes import RunningOrder
ro = RunningOrder.from_file('123456-roCreate.mos.xml')
print(ro.ro_slug)
for story in ro.stories:
print(story.slug)
Here, ro.stories
is a list of Story
objects.
Each story has its own set of accessible properties, such as the story’s
duration
,
start_time
,
end_time
,
offset
and
items
:
>>> story = ro.stories[0]
>>> story.duration
180.0
>>> story.start_time
datetime.datetime(2021, 4, 8, 21, 46, 30)
>>> len(story.items)
3
Here, the story contains 3 items, each of these is an
Item
object.
MOS Collection
The MOS Collection part of the module provides a wrapper class
MosCollection
which stores references to
specified MOS files, strings or S3 object keys so the
MosFile
objects can be recreated when needed rather
than kept in memory. Rather than using the +
operator, a
merge()
method is provided:
from mosromgr.moscollection import MosCollection
mc = MosCollection.from_s3(bucket_name=bucket_name, prefix=prefix)
mc.merge()
The next page will cover some example problems and solutions to show you how you can use mosromgr in practice.