comments migration
This commit is contained in:
parent
3172622360
commit
b5ab1efc6a
32
migrate.py
32
migrate.py
|
@ -143,6 +143,34 @@ def shouts():
|
||||||
' content items were migrated')
|
' content items were migrated')
|
||||||
print(str(discours_author) + ' from them by @discours')
|
print(str(discours_author) + ' from them by @discours')
|
||||||
|
|
||||||
|
def comments():
|
||||||
|
''' migrating comments on content items one by one '''
|
||||||
|
comments_data = json.loads(open('migration/data/comments.json').read())
|
||||||
|
print(str(len(comments_data)) + ' comments loaded')
|
||||||
|
comments_by_post = {}
|
||||||
|
for comment in comments_data:
|
||||||
|
p = comment['contentItem']
|
||||||
|
comments_by_post[p] = comments_by_post.get(p, [])
|
||||||
|
comments_by_post[p].append(comment)
|
||||||
|
export_articles = json.loads(open('../src/data/articles.json').read())
|
||||||
|
print(str(len(export_articles.items())) + ' articles were exported')
|
||||||
|
export_comments = {}
|
||||||
|
c = 0
|
||||||
|
for article in export_articles:
|
||||||
|
print(article['slug'])
|
||||||
|
print( comments_by_post.get(article['slug'], '') )
|
||||||
|
print( export_comments[article['slug']] ) # = comments_by_post.get(article['slug'])
|
||||||
|
c += len(export_comments[article['slug']])
|
||||||
|
print(str(len(export_comments.items())) + ' articles with comments')
|
||||||
|
open('../src/data/coments.json', 'w').write(json.dumps(dict(export_comments),
|
||||||
|
cls=DateTimeEncoder,
|
||||||
|
indent=4,
|
||||||
|
sort_keys=True,
|
||||||
|
ensure_ascii=False))
|
||||||
|
print(str(c) + ' comments were exported')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def export_shouts(limit):
|
def export_shouts(limit):
|
||||||
print('reading json...')
|
print('reading json...')
|
||||||
newdata = json.loads(open('migration/data/shouts.dict.json', 'r').read())
|
newdata = json.loads(open('migration/data/shouts.dict.json', 'r').read())
|
||||||
|
@ -182,6 +210,7 @@ def export_shouts(limit):
|
||||||
indent=4,
|
indent=4,
|
||||||
sort_keys=True,
|
sort_keys=True,
|
||||||
ensure_ascii=False))
|
ensure_ascii=False))
|
||||||
|
comments()
|
||||||
print(str(len(export_authors.items())) + ' total authors exported')
|
print(str(len(export_authors.items())) + ' total authors exported')
|
||||||
|
|
||||||
def export_slug(slug):
|
def export_slug(slug):
|
||||||
|
@ -209,6 +238,7 @@ def export_slug(slug):
|
||||||
indent=4,
|
indent=4,
|
||||||
sort_keys=True,
|
sort_keys=True,
|
||||||
ensure_ascii=False))
|
ensure_ascii=False))
|
||||||
|
comments()
|
||||||
print('exported.')
|
print('exported.')
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,6 +249,8 @@ if __name__ == '__main__':
|
||||||
users()
|
users()
|
||||||
elif sys.argv[1] == "topics":
|
elif sys.argv[1] == "topics":
|
||||||
topics()
|
topics()
|
||||||
|
elif sys.argv[1] == "comments":
|
||||||
|
comments()
|
||||||
elif sys.argv[1] == "shouts":
|
elif sys.argv[1] == "shouts":
|
||||||
try:
|
try:
|
||||||
Community.create(**{
|
Community.create(**{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user