mirror of
https://github.com/ilri/csv-metadata-quality.git
synced 2024-11-22 05:45:02 +01:00
csv_metadata_quality/check.py: Prune requests cache once
We only need to prune the requests cache once before using it, not for every value we check.
This commit is contained in:
parent
aa9e23b46c
commit
5fcaa63bd5
@ -221,23 +221,23 @@ def agrovoc(field, field_name):
|
|||||||
if pd.isna(field):
|
if pd.isna(field):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# enable transparent request cache with thirty days expiry
|
||||||
|
expire_after = timedelta(days=30)
|
||||||
|
requests_cache.install_cache(
|
||||||
|
"agrovoc-response-cache", expire_after=expire_after
|
||||||
|
)
|
||||||
|
|
||||||
|
# prune old cache entries
|
||||||
|
requests_cache.core.remove_expired_responses()
|
||||||
|
|
||||||
# Try to split multi-value field on "||" separator
|
# Try to split multi-value field on "||" separator
|
||||||
for value in field.split("||"):
|
for value in field.split("||"):
|
||||||
request_url = (
|
request_url = (
|
||||||
f"http://agrovoc.uniroma2.it/agrovoc/rest/v1/agrovoc/search?query={value}"
|
f"http://agrovoc.uniroma2.it/agrovoc/rest/v1/agrovoc/search?query={value}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# enable transparent request cache with thirty days expiry
|
|
||||||
expire_after = timedelta(days=30)
|
|
||||||
requests_cache.install_cache(
|
|
||||||
"agrovoc-response-cache", expire_after=expire_after
|
|
||||||
)
|
|
||||||
|
|
||||||
request = requests.get(request_url)
|
request = requests.get(request_url)
|
||||||
|
|
||||||
# prune old cache entries
|
|
||||||
requests_cache.core.remove_expired_responses()
|
|
||||||
|
|
||||||
if request.status_code == requests.codes.ok:
|
if request.status_code == requests.codes.ok:
|
||||||
data = request.json()
|
data = request.json()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user