core/migration/tables/remarks.py

43 lines
1.3 KiB
Python
Raw Normal View History

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
def migrate(entry, storage):
2023-10-26 21:07:35 +00:00
post_oid = entry['contentItem']
print(post_oid)
2023-10-26 21:07:35 +00:00
shout_dict = storage['shouts']['by_oid'].get(post_oid)
2023-01-17 19:56:48 +00:00
if shout_dict:
2023-10-26 21:07:35 +00:00
print(shout_dict['body'])
2023-01-17 19:56:48 +00:00
remark = {
2023-10-26 21:07:35 +00:00
"shout": shout_dict['id'],
"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-10-26 21:07:35 +00:00
if entry.get('textBefore'):
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
)
with local_session() as session:
rmrk = Reaction.create(**remark)
session.commit()
del rmrk["_sa_instance_state"]
return rmrk
return