def migrate(coll_name='article', limit=10): res = { "meta": { "exported_on": cur_timestamp(), "version": "003" } } coll = get_collection(DB, coll_name) posts = [] posts_tags = [] index = 0 for doc in coll.find().batch_size(1000): title = doc.get('title') if not exist_or_insert(title): doc_id = doc.get('_id') post_id = int(doc['source_url'].rsplit('/', 1)[1].split('.')[0]) index += 1 if index > limit: break posts.append(replace_post(doc)) posts_tags.append( {"tag_id": 1, "post_id": post_id} ) data = { "posts": posts, "tags": TAGS, "posts_tags": posts_tags, "users": USERS } res["data"] = data return res
def migrate(coll_name='article_pyhome', skip=0, limit=10): res = {"meta": {"exported_on": cur_timestamp(), "version": "003"}} coll = get_collection(DB, coll_name) posts = [] posts_tags = [] slug_set = set() for doc in coll.find().skip(skip).limit(limit): title = doc.get('title') slug = title.lower().strip() if slug and (slug not in slug_set): slug_set.add(slug) doc['slug'] = slug if not exist_or_insert(slug): doc_id = doc.get('_id') post_id = int(doc['source_url'].rsplit('/', 1)[1].split('.')[0]) posts.append(replace_post(doc)) posts_tags.append({"tag_id": 1, "post_id": post_id}) data = { "posts": posts, "tags": TAGS, "posts_tags": posts_tags, "users": USERS } res["data"] = data return res
def migrate(coll_name, limit=10): coll = get_collection(DB, coll_name) # gen_tag_id() # gen tag first res = { "meta": { "exported_on": cur_timestamp(), "version": "003" } } posts = [] posts_tags = [] index = 0 slug_set = set() for doc in coll.find().sort('time', -1).batch_size(1000): if is_python_article(doc): title = doc.get('title') if not exist_or_insert(title): doc_id = doc.get('_id') index += 1 if index > limit: break slug = doc.get('title') if len(slug) > 30: slug = slug[0:30] doc['title'] = slug if slug not in slug_set: slug_set.add(slug) posts.append(replace_post(doc)) posts_tags.append( {"tag_id": TAGS[0].get('id'), "post_id": int(doc_id)} ) data = { "posts": posts, "tags": TAGS, "posts_tags": posts_tags, "users": USERS } res["data"] = data return res
def migrate(coll_name, limit=10): coll = get_collection(DB, coll_name) # gen_tag_id() # gen tag first res = { "meta": { "exported_on": cur_timestamp(), "version": "003" } } posts = [] posts_tags = [] index = 0 slug_set = set() for doc in coll.find().sort('time', -1).batch_size(1000): title = doc.get('title') if not exist_or_insert(title): doc_id = doc.get('_id') index += 1 if index > limit: break slug = doc.get('title') if len(slug) > 30: slug = slug[0:30] doc['title'] = slug if slug not in slug_set: slug_set.add(slug) posts.append(replace_post(doc)) posts_tags.append( {"tag_id": TAGS[0].get('id'), "post_id": int(doc_id)} ) data = { "posts": posts, "tags": TAGS, "posts_tags": posts_tags, "users": USERS } res["data"] = data return res
def migrate(coll_name, limit=10): res = { "meta": { "exported_on": cur_timestamp(), "version": "003" } } coll = get_collection(DB, coll_name) posts = [] posts_tags = [] index = 0 title_set = set() for doc in coll.find().batch_size(1000): title = doc.get('title') slug = title.lower().strip() if slug not in title_set: title_set.add(slug) if not exist_or_insert(slug): doc_id = doc.get('_id') post_id = int(doc['source_url'].rsplit('/', 1)[1].split('.')[0]) index += 1 if index > limit: break posts.append(replace_post(doc)) posts_tags.append( {"tag_id": 1000, "post_id": post_id} ) data = { "posts": posts, "tags": TAGS, "posts_tags": posts_tags, "users": USERS } res["data"] = data return res