Skip to content

Commit

Permalink
Update v110.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SeoulSKY committed Feb 27, 2024
1 parent a9de66b commit c2db72c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/firestore_to_mongo.py → scripts/v103.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def main():
"""

if len(sys.argv) != 3:
print("Usage: python firestore_to_mongo.py <path/to/service_account.json> <host>")
print("Usage: python v103.py <path/to/service_account.json> <host>")
sys.exit(1)

app = firebase_admin.initialize_app(credentials.Certificate(sys.argv[1]))
Expand Down
18 changes: 14 additions & 4 deletions scripts/language_name_to_code.py → scripts/v110.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Replace the translate_to field with language code in MongoDB
Migrate to v1.1.0
"""

import asyncio
Expand All @@ -19,7 +19,7 @@
NAME_TO_CODE = GoogleTranslator().get_supported_languages(as_dict=True)


async def replace(collection: AsyncIOMotorCollection):
async def replace_translate_to(collection: AsyncIOMotorCollection):
"""
Replace the translate_to field with language code
"""
Expand All @@ -37,8 +37,18 @@ async def main():
"""
Main function
"""
await replace(user_collection)
await replace(channel_collection)
await replace_translate_to(user_collection)
await replace_translate_to(channel_collection)

pbar = tqdm(desc="Updating main_language", total=await user_collection.count_documents({}), unit="doc")
async for doc in user_collection.find():
pbar.update(1)
doc["locale"] = NAME_TO_CODE.get(doc["main_language"], doc["main_language"])
doc.pop("main_language", None)
doc.pop("chat_history_tgt", None)
await user_collection.replace_one({"_id": doc["_id"]}, doc)

pbar.close()


if __name__ == "__main__":
Expand Down

0 comments on commit c2db72c

Please sign in to comment.