fixing-wip

This commit is contained in:
2023-01-17 22:56:48 +03:00
parent b966ce6c24
commit 82c6236a7f
8 changed files with 106 additions and 99 deletions

View File

@@ -1,31 +1,42 @@
from base.orm import local_session
from migration.extract import extract_md
from migration.html2text import html2text
from orm.remark import Remark
from orm.reaction import Reaction, ReactionKind
def migrate(entry, storage):
post_oid = entry['contentItem']
print(post_oid)
shout_dict = storage['shouts']['by_oid'].get(post_oid)
remark = {
"shout": shout_dict['id'],
"body": extract_md(
html2text(entry['body']),
entry['_id']
),
"desc": extract_md(
html2text(
entry['textAfter'] or '' + \
entry['textBefore'] or '' + \
entry['textSelected'] or ''
if shout_dict:
print(shout_dict['body'])
remark = {
"shout": shout_dict['id'],
"body": extract_md(
html2text(entry['body']),
shout_dict
),
entry["_id"]
)
}
"kind": ReactionKind.REMARK
}
with local_session() as session:
rmrk = Remark.create(**remark)
session.commit()
del rmrk["_sa_instance_state"]
return rmrk
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 ''
)
)
with local_session() as session:
rmrk = Reaction.create(**remark)
session.commit()
del rmrk["_sa_instance_state"]
return rmrk
return