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