Skip to content

Commit

Permalink
fix: add tags from Zotero to references collection
Browse files Browse the repository at this point in the history
resolves #98
  • Loading branch information
sennierer committed May 21, 2024
1 parent 14c67ba commit 7353001
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion viecpro_typesense/collections.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .handlers import GenericDocIDHandler
from .handlers import GenericDocIDHandler, ZoteroTagHandler
from viecpro_typesense import Collection, StaticField, CollectionConfig, O, Field
from copy import deepcopy
from .fields import StringField, FullNameField, TitlesNestedObjectField, RelationTypeHierarchyHandler, WrittenDateField, BibtexShortTitleHandler, BibtexTitleHandler, BibtexTypeHandler, RelatedReferenceDocField, ObjectIDField, DateObjectDateField, LabelsNestedObjectField, KindField, SourceField, TargetField, HofstaatsinhaberField, MainOwnerField, FunctionsArrayField, PersonInstitutionArrayField
Expand Down Expand Up @@ -26,6 +26,8 @@ class Config:
"bibtex", handler=BibtexShortTitleHandler, options=O(facet=True, optional=True))
kind = StringField("bibtex", handler=BibtexTypeHandler,
options=O(facet=True, optional=True))
tag = StringField("url", handler=ZoteroTagHandler,
options=O(facet=True, optional=False))
related_doc = RelatedReferenceDocField(
("content_type", "object_id"), options=O(facet=True, optional=True))

Expand Down
14 changes: 14 additions & 0 deletions viecpro_typesense/handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import requests
from apis_core.apis_vocabularies.models import VocabsBaseClass
from viecpro_typesense.classes import Handler
import json
Expand Down Expand Up @@ -152,6 +154,18 @@ def func(bibtex):
bib = json.loads(bibtex)
return bib.get("type", "")

class ZoteroTagHandler(Handler):
def func(zotero_url):
json = requests.get(
zotero_url, params={"key": os.environ.get("ZOTERO_API_KEY")}
).json()
tags = json["data"].get("tags")
tag_group = [tag["tag"][2:] for tag in tags if tag["tag"].startswith("1_")]
if len(tag_group) == 1:
return tag_group[0]
else:
return "Allgemein"


class HofstaatsinhaberHandler(Handler):

Expand Down

0 comments on commit 7353001

Please sign in to comment.