This commit is contained in:
2025-05-16 14:29:14 -03:00
parent 17131380ac
commit cc9bd08daa
49 changed files with 177 additions and 54 deletions

View File

@@ -0,0 +1,62 @@
import pprint
from meilisearch import Client as Meilisearch
MASTER_KEY = 'zrYPsSAG1hgq2zB1dkF0sB9xLoIwTLAz6uw38pWRf5abdpTjY2eeMTIsfPbDbqQR'
API_KEY = '1aa4c720611269e9425e8467df7e802f3a20ad6c5f31fe875ac886fc4efa2c83'
client = Meilisearch(
# 'https://meili.vps.eduseg.com.br',
# '1aa4c720611269e9425e8467df7e802f3a20ad6c5f31fe875ac886fc4efa2c83',
'http://localhost:7700'
)
pp = pprint.PrettyPrinter(indent=4)
courses = client.index('test-courses')
courses.update_settings(
{
'sortableAttributes': ['create_date'],
'filterableAttributes': ['tenant__org_id'],
}
)
# with open('cli/search-results.json') as fp:
# docs = json.load(fp)
# courses.add_documents(docs)
# pp.pprint(courses.search(''))
# client.create_index('betaeducacao-prod-orders', {'primaryKey': 'id'})
# client.create_index('betaeducacao-prod-enrollments', {'primaryKey': 'id'})
# client.create_index('betaeducacao-prod-users_d2o3r5gmm4it7j', {'primaryKey': 'id'})
# An index is where the documents are stored.
# index = client.index('users')
# pp.pprint(index.search(query='*'))
# documents = [
# {'id': 1, 'title': 'Carol', 'genres': ['Romance', 'Drama']},
# {'id': 2, 'title': 'Wonder Woman', 'genres': ['Action', 'Adventure']},
# {'id': 3, 'title': 'Life of Pi', 'genres': ['Adventure', 'Drama']},
# {
# 'id': 4,
# 'title': 'Mad Max: Fury Road',
# 'genres': ['Adventure', 'Science Fiction'],
# },
# {'id': 5, 'title': 'Moana', 'genres': ['Fantasy', 'Action']},
# {'id': 6, 'title': 'Philadelphia', 'genres': ['Drama']},
# ]
# # # If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
# index.add_documents(documents
#
# )
# pp.pprint(client.get_keys({'limit': 3}).model_dump_json())
#
# uid='fdbdda56-00dd-4f53-934f-6629f3b08ee3' name=None description='Add, get documents and search' actions=['documents.add', 'documents.get', 'search'] indexes=['users', 'courses', 'enrollments', 'orders'] expires_at=None key='1aa4c720611269e9425e8467df7e802f3a20ad6c5f31fe875ac886fc4efa2c83' created_at=datetime.datetime(2025, 4, 1, 0, 46, 27, 751365) updated_at=datetime.datetime(2025, 4, 1, 0, 46, 27, 751365)

8
http-api/cli/ddb.py Normal file
View File

@@ -0,0 +1,8 @@
import json
from layercake.dynamodb import serialize
with open('cli/search-results.json') as fp:
docs = json.load(fp)
for doc in docs:
print(json.dumps(serialize(doc)))

View File

@@ -1,8 +1,8 @@
from typing import Any, Generator
import boto3
import jsonlines
from elasticsearch import Elasticsearch
import jsonlines
from layercake.dynamodb import deserialize
from tqdm import tqdm

40
http-api/cli/unzip.py Normal file
View File

@@ -0,0 +1,40 @@
import gzip
from pathlib import Path
def unzip_gzip(file: Path, target: str):
with gzip.open(file, 'rb') as r:
with open(target, 'wb') as w:
return w.write(r.read())
def unzip_gzfiles(dirpath: Path) -> None:
"""Unzip the .gz files from a dir."""
if not dirpath.exists() or not dirpath.is_dir():
print(f'"{dirpath}" not found')
return None
gzfiles = list(dirpath.glob('*.gz'))
if not gzfiles:
print(f'No .gz files found in "{dirpath}"')
return None
# Create a directory to output the files
Path(f'{dirpath}/out').mkdir(exist_ok=True)
for file in gzfiles:
filename = file.name.removesuffix('.gz')
if not file.is_file():
continue
if unzip_gzip(file, f'{dirpath}/out/{filename}'):
print(f'Unzipped "{file.name}"')
if __name__ == '__main__':
try:
dirpath = input('Type the directory path\n')
unzip_gzfiles(Path(dirpath))
except (KeyboardInterrupt, Exception):
print('See ya')