Fix synchronization of Twitch comments

master
Nikola Forró 6 years ago
parent c553d75cc9
commit 8245e5af29

@ -128,7 +128,7 @@ class CommentResource(flask_restful.Resource):
if not video: if not video:
flask_restful.abort(404, message='Video {0} does not exist'.format(video_id)) flask_restful.abort(404, message='Video {0} does not exist'.format(video_id))
q = db.session.query(Association).join(Comment).filter( q = db.session.query(Association).join(Comment).filter(
Association.video_id == video_id, Comment.id == comment_id) Association.video_id == video_id, Association.comment_id == comment_id)
assoc = q.first() assoc = q.first()
if not assoc: if not assoc:
flask_restful.abort(404, flask_restful.abort(404,

@ -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()

Loading…
Cancel
Save