2023-01-17 06:19:12 +00:00
|
|
|
from base.orm import local_session
|
|
|
|
from migration.extract import extract_md
|
|
|
|
from migration.html2text import html2text
|
2023-01-17 19:56:48 +00:00
|
|
|
from orm.reaction import Reaction, ReactionKind
|
2023-01-17 06:19:12 +00:00
|
|
|
|
|
|
|
|
2023-01-17 09:11:18 +00:00
|
|
|
def migrate(entry, storage):
|
|
|
|
post_oid = entry['contentItem']
|
|
|
|
print(post_oid)
|
|
|
|
shout_dict = storage['shouts']['by_oid'].get(post_oid)
|
2023-01-17 19:56:48 +00:00
|
|
|
if shout_dict:
|
|
|
|
print(shout_dict['body'])
|
|
|
|
remark = {
|
|
|
|
"shout": shout_dict['id'],
|
2023-10-26 17:56:42 +00:00
|
|
|
"body": extract_md(html2text(entry['body']), shout_dict),
|
|
|
|
"kind": ReactionKind.REMARK,
|
2023-01-17 19:56:48 +00:00
|
|
|
}
|
2023-01-17 06:19:12 +00:00
|
|
|
|
2023-01-17 19:56:48 +00:00
|
|
|
if entry.get('textBefore'):
|
2023-10-26 17:56:42 +00:00
|
|
|
remark['range'] = (
|
|
|
|
str(shout_dict['body'].index(entry['textBefore'] or ''))
|
|
|
|
+ ':'
|
|
|
|
+ str(
|
|
|
|
shout_dict['body'].index(entry['textAfter'] or '')
|
|
|
|
+ len(entry['textAfter'] or '')
|
2023-01-17 19:56:48 +00:00
|
|
|
)
|
2023-10-26 17:56:42 +00:00
|
|
|
)
|
2023-01-17 19:56:48 +00:00
|
|
|
|
|
|
|
with local_session() as session:
|
|
|
|
rmrk = Reaction.create(**remark)
|
|
|
|
session.commit()
|
|
|
|
del rmrk["_sa_instance_state"]
|
|
|
|
return rmrk
|
|
|
|
return
|