-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathalgolia.py
More file actions
28 lines (18 loc) · 689 Bytes
/
algolia.py
File metadata and controls
28 lines (18 loc) · 689 Bytes
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
import os
import csv
from algoliasearch.search_client import SearchClient
client = SearchClient.create("08KMSERF1B", str(os.environ.get("KEY")))
index = client.init_index("Project")
def add_records(filename: str):
with open(filename, newline="") as f:
csv_r = list(csv.DictReader(f, delimiter=";"))
len_idx = index.search("")["nbHits"]
if len(csv_r) > len_idx:
index.save_objects(
csv_r[len_idx:], {"autoGenerateObjectIDIfNotExist": "true"}
)
print(f"{len(csv_r[len_idx:])} new records added.")
return
print("Nothing new.")
if __name__ == "__main__":
add_records("projects.csv")