Skip to content

Instantly share code, notes, and snippets.

@datadavev
Last active March 12, 2024 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save datadavev/2ca265f34eccc502b28dcc71559f2a9e to your computer and use it in GitHub Desktop.
Save datadavev/2ca265f34eccc502b28dcc71559f2a9e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import urllib.parse
import urllib.request
import ijson
def stream_records(q:str):
fields = [
"id",
"source",
"label",
"hasMaterialCategory",
"hasSpecimenCategory",
"hasContextCategory",
"keywords",
"producedBy_label",
"producedBy_description",
"producedBy_responsibility",
"producedBy_resultTime",
"producedBy_samplingSite_label",
"producedBy_samplingSite_location_latitude",
"producedBy_samplingSite_location_longitude",
"curation_responsibility",
"relatedResource_isb_core_id",
]
params = {
"q":q,
"sort":"id asc",
"fl": ",".join(fields),
"wt":"json"
}
url = "http://localhost:8983/solr/isb_core_records/export"
url = f"{url}?{urllib.parse.urlencode(params)}"
print(url)
src = urllib.request.urlopen(url)
docs = ijson.items(src, "response.docs.item")
counter = 0
for doc in docs:
if counter % 10000 == 0:
print(f"{counter:07}")
counter += 1
print(f"Total = {counter}")
q = "source:GEOME"
stream_records(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment