|
|
@ -68,11 +68,19 @@ class Sync(object):
|
|
|
|
db.session.add(video)
|
|
|
|
db.session.add(video)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
app.logger.info('Updated videos: %s', ', '.join(updated) if updated else 'NONE')
|
|
|
|
app.logger.info('Updated videos: %s', ', '.join(updated) if updated else 'NONE')
|
|
|
|
|
|
|
|
comments = {}
|
|
|
|
for com in twitch.fetch_comments(updated):
|
|
|
|
for com in twitch.fetch_comments(updated):
|
|
|
|
q = db.session.query(Video).filter(Video.id == cls._get(com, 'content_id'))
|
|
|
|
id = cls._get(com, '_id')
|
|
|
|
video = q.first()
|
|
|
|
assoc = dict(
|
|
|
|
if not video:
|
|
|
|
video_id=cls._get(com, 'content_id'),
|
|
|
|
continue
|
|
|
|
offset=cls._get(com, 'content_offset_seconds'))
|
|
|
|
|
|
|
|
if id in comments:
|
|
|
|
|
|
|
|
comments[id].update(com)
|
|
|
|
|
|
|
|
comments[id]['assocs'].append(assoc)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
comments[id] = com
|
|
|
|
|
|
|
|
comments[id]['assocs'] = [assoc]
|
|
|
|
|
|
|
|
for com in comments.values():
|
|
|
|
id = cls._get(com, '_id')
|
|
|
|
id = cls._get(com, '_id')
|
|
|
|
q = db.session.query(Comment).filter(Comment.id == id)
|
|
|
|
q = db.session.query(Comment).filter(Comment.id == id)
|
|
|
|
comment = q.first()
|
|
|
|
comment = q.first()
|
|
|
@ -91,16 +99,21 @@ class Sync(object):
|
|
|
|
comment.message_user_badges = badges
|
|
|
|
comment.message_user_badges = badges
|
|
|
|
comment.created_at = cls._to_datetime(cls._get(com, 'created_at'))
|
|
|
|
comment.created_at = cls._to_datetime(cls._get(com, 'created_at'))
|
|
|
|
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(
|
|
|
|
for assc in com['assocs']:
|
|
|
|
Association.video_id == video.id,
|
|
|
|
q = db.session.query(Video).filter(Video.id == assc['video_id'])
|
|
|
|
Association.comment_id == comment.id)
|
|
|
|
video = q.first()
|
|
|
|
assoc = q.first()
|
|
|
|
if not video:
|
|
|
|
if not assoc:
|
|
|
|
continue
|
|
|
|
assoc = Association()
|
|
|
|
q = db.session.query(Association).filter(
|
|
|
|
assoc.comment = comment
|
|
|
|
Association.video_id == video.id,
|
|
|
|
assoc.offset = cls._get(com, 'content_offset_seconds')
|
|
|
|
Association.comment_id == comment.id)
|
|
|
|
video.associations.append(assoc)
|
|
|
|
assoc = q.first()
|
|
|
|
db.session.add(video)
|
|
|
|
if not assoc:
|
|
|
|
|
|
|
|
assoc = Association()
|
|
|
|
|
|
|
|
assoc.comment = comment
|
|
|
|
|
|
|
|
assoc.offset = assc['offset']
|
|
|
|
|
|
|
|
video.associations.append(assoc)
|
|
|
|
|
|
|
|
db.session.add(video)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
app.logger.info('Synchronization of videos completed')
|
|
|
|
app.logger.info('Synchronization of videos completed')
|
|
|
|
|
|
|
|
|
|
|
|