migration fixed, export wip

This commit is contained in:
Untone 2021-10-16 11:27:17 +03:00
parent 2a6baa7404
commit 00942e985b
2 changed files with 6 additions and 9 deletions

View File

@ -49,7 +49,7 @@ if __name__ == '__main__':
for old_comment in comments_data: for old_comment in comments_data:
cid = old_comment['contentItem'] cid = old_comment['contentItem']
comments_by_post[cid] = comments_by_post.get(cid, []) comments_by_post[cid] = comments_by_post.get(cid, [])
if 'deletedAt' not in old_comment: if not old_comment.get('deletedAt', True):
comments_by_post[cid].append(old_comment) comments_by_post[cid].append(old_comment)
print(str(len(comments_by_post.keys())) + ' articles with comments') print(str(len(comments_by_post.keys())) + ' articles with comments')
@ -299,10 +299,6 @@ if __name__ == '__main__':
except Exception: except Exception:
pass pass
shouts(shouts_by_slug, shouts_by_oid) # NOTE: listens limit shouts(shouts_by_slug, shouts_by_oid) # NOTE: listens limit
elif cmd == "comments":
cl = sys.argv[2] if len(sys.argv) > 2 else 10
topCommented = sorted([ c[0] for c in comments_by_post.items()], reverse=True, key=lambda i: len(i[1]))[-cl:]
comments(topCommented, export_comments, export_articles, shouts_by_slug, content_dict)
elif cmd == "export_shouts": elif cmd == "export_shouts":
export_shouts(shouts_by_slug, export_articles, export_authors, content_dict) export_shouts(shouts_by_slug, export_articles, export_authors, content_dict)
elif cmd == "all": elif cmd == "all":
@ -310,8 +306,9 @@ if __name__ == '__main__':
topics(export_topics, topics_by_slug, topics_by_cat, topics_by_tag, cats_data, tags_data) topics(export_topics, topics_by_slug, topics_by_cat, topics_by_tag, cats_data, tags_data)
shouts(content_data, shouts_by_slug, shouts_by_oid) shouts(content_data, shouts_by_slug, shouts_by_oid)
cl = sys.argv[2] if len(sys.argv) > 2 else 10 cl = sys.argv[2] if len(sys.argv) > 2 else 10
topCommented = sorted([ c[0] for c in comments_by_post.items()], reverse=True, key=lambda i: len(i[1]))[-cl:] topOids = sorted([ c[0] for c in comments_by_post.items()], reverse=True, key=lambda i: len(i[1]))[-cl:]
comments(topCommented, export_comments, export_articles, shouts_by_slug, content_dict) topSlugs = [ shouts_by_oid[oid]['slug'] for oid in topOids ]
comments(topSlugs, export_comments, export_articles, shouts_by_slug, content_dict)
elif cmd == "bson": elif cmd == "bson":
from migration import bson2json from migration import bson2json
bson2json.json_tables() bson2json.json_tables()
@ -324,7 +321,6 @@ if __name__ == '__main__':
\n.. \ttopics <limit> \n.. \ttopics <limit>
\n.. \tusers <limit> \n.. \tusers <limit>
\n.. \tshouts <limit> \n.. \tshouts <limit>
\n.. \tcomments
\n.. \texport_shouts <limit> \n.. \texport_shouts <limit>
\n.. \tslug <slug> \n.. \tslug <slug>
\n.. \tall \n.. \tall

View File

@ -140,13 +140,14 @@ def migrate(entry, users_by_oid, topics_by_oid):
except KeyError: except KeyError:
app = entry.get('application') app = entry.get('application')
if app: if app:
userslug = translit(app['name'], 'ru', reversed=True).replace(' ', '-').replace('\'', '').replace('.', '-').lower()
userdata = { userdata = {
'username': app['email'], 'username': app['email'],
'email': app['email'], 'email': app['email'],
'name': app['name'], 'name': app['name'],
'bio': app.get('bio', ''), 'bio': app.get('bio', ''),
'emailConfirmed': False, 'emailConfirmed': False,
'slug': translit(app['name'], 'ru', reversed=True).replace(' ', '-').replace('\'', '').lower(), 'slug': userslug,
'createdAt': ts, 'createdAt': ts,
'wasOnlineAt': ts 'wasOnlineAt': ts
} }