|
|
|
@ -74,24 +74,31 @@ class Sync(object):
|
|
|
|
|
if not video:
|
|
|
|
|
continue
|
|
|
|
|
id = cls._get(com, '_id')
|
|
|
|
|
q = db.session.query(Association).filter(Video.id == video.id, Comment.id == id)
|
|
|
|
|
assoc = q.first()
|
|
|
|
|
if not assoc:
|
|
|
|
|
assoc = Association(comment=Comment(id=id))
|
|
|
|
|
assoc.offset=cls._get(com, 'content_offset_seconds')
|
|
|
|
|
assoc.comment.commenter_id = cls._get(com, 'commenter', '_id')
|
|
|
|
|
assoc.comment.commenter_name = cls._get(com, 'commenter', 'name')
|
|
|
|
|
assoc.comment.commenter_display_name = cls._get(com, 'commenter', 'display_name')
|
|
|
|
|
assoc.comment.commenter_logo = cls._get(com, 'commenter', 'logo')
|
|
|
|
|
assoc.comment.source = cls._get(com, 'source')
|
|
|
|
|
assoc.comment.message_body = cls._get(com, 'message', 'body')
|
|
|
|
|
assoc.comment.message_user_color = cls._get(com, 'message', 'user_color')
|
|
|
|
|
q = db.session.query(Comment).filter(Comment.id == id)
|
|
|
|
|
comment = q.first()
|
|
|
|
|
if not comment:
|
|
|
|
|
comment = Comment(id=id)
|
|
|
|
|
comment.commenter_id = cls._get(com, 'commenter', '_id')
|
|
|
|
|
comment.commenter_name = cls._get(com, 'commenter', 'name')
|
|
|
|
|
comment.commenter_display_name = cls._get(com, 'commenter', 'display_name')
|
|
|
|
|
comment.commenter_logo = cls._get(com, 'commenter', 'logo')
|
|
|
|
|
comment.source = cls._get(com, 'source')
|
|
|
|
|
comment.message_body = cls._get(com, 'message', 'body')
|
|
|
|
|
comment.message_user_color = cls._get(com, 'message', 'user_color')
|
|
|
|
|
badges = cls._get(com, 'message', 'user_badges')
|
|
|
|
|
if badges:
|
|
|
|
|
badges = ','.join(['{_id}:{version}'.format(**b) for b in badges])
|
|
|
|
|
assoc.comment.message_user_badges = badges
|
|
|
|
|
assoc.comment.created_at = cls._to_datetime(cls._get(com, 'created_at'))
|
|
|
|
|
assoc.comment.updated_at = cls._to_datetime(cls._get(com, 'updated_at'))
|
|
|
|
|
comment.message_user_badges = badges
|
|
|
|
|
comment.created_at = cls._to_datetime(cls._get(com, 'created_at'))
|
|
|
|
|
comment.updated_at = cls._to_datetime(cls._get(com, 'updated_at'))
|
|
|
|
|
q = db.session.query(Association).filter(
|
|
|
|
|
Association.video_id == video.id,
|
|
|
|
|
Association.comment_id == comment.id)
|
|
|
|
|
assoc = q.first()
|
|
|
|
|
if not assoc:
|
|
|
|
|
assoc = Association()
|
|
|
|
|
assoc.comment = comment
|
|
|
|
|
assoc.offset = cls._get(com, 'content_offset_seconds')
|
|
|
|
|
video.associations.append(assoc)
|
|
|
|
|
db.session.add(video)
|
|
|
|
|
db.session.commit()
|
|
|
|
|