Tutorials / Articles » Synchronizing Content for Syndication
Posted by Revver Developer Team
Related Topics: Tech Talk, Python, Syndication, API
A common use case for Revver media is to create a local store of videos and then keep this store up to date. This is commonly used by large syndication partners, but can be used by anyone wishing to keep track of changed videos in the Revver library.
In a given hour, 100 or so videos might get updated, and rather than constantly pull the same queries over and over, it’s helpful to have a “delta” of what has changed and much like rsync, just update the information you need. This can also be useful for tracking updates made by your users.
This can be done rather easily, using the modifiedWithin query key and the ‘final’ option key.
Example:
#!/usr/bin/python
import xmlrpclib, sys
s = xmlrpclib.Server(
'https://api.revver.com/xml/1.0?login=username&passwd=passwd'
)
query = dict(
modifiedWithin=60*60*24, # in the last 24 hours
statuses = ['all']
returnFields = ['id',
'title',
'owner',
'modifiedDate',
'status']
videos = []
done = False
offset = 0
while not done:
page = s.video.find(query, returnFields, dict(
orderBy=('modifiedDate', False),
final=True,
offset = offset
))
offset += len(page['result'])
videos.extend(page['result'])
done = page['final']
for video in videos:
print "%-10s %-30s %-10s %-20s %s" % (
video['id'],
video['owner'],
video['modifiedDate'],
video['status'],
video['title'])
print
print "%s videos modified since last pull" % len(videos)
Note: Be sure when using loop constructs that accept boolean values that you give yourself a maximum loop count, so in cause you mistype something you don’t end up in an infinite loop.
No Comments »
No comments yet.
RSS feed for comments on this post.
Leave a comment
You must be logged in to post a comment.
