forked from mawoka-myblock/ClassQuiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_to_meili.py
31 lines (25 loc) · 1.06 KB
/
import_to_meili.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import meilisearch
from classquiz.db import database
from classquiz.db.models import Quiz
from classquiz.helpers import get_meili_data
from classquiz.config import settings
from asyncio import run
settings = settings()
async def __main__():
if not database.is_connected:
await database.connect()
meili_data = []
quizzes = await Quiz.objects.filter(public=True).all()
for quiz in quizzes:
meili_data.append(await get_meili_data(quiz))
print(len(meili_data))
client = meilisearch.Client(settings.meilisearch_url)
client.delete_index(settings.meilisearch_index)
client.create_index(settings.meilisearch_index)
client.index(settings.meilisearch_index).add_documents(meili_data)
client.index(settings.meilisearch_index).update_settings({"sortableAttributes": ["created_at"]})
if __name__ == "__main__":
run(__main__())