Skip to content

Commit 3e06798

Browse files
Merge pull request #245 from ARGA-Genomes/gbif
GBIF
2 parents 7738aa6 + 76395bc commit 3e06798

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

dataSources/gbif/api/config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"retrieveType": "script",
3+
"downloading": {
4+
"path": "./processing.py",
5+
"function": "collect",
6+
"args": [
7+
"{OUT-PATH}"
8+
],
9+
"output": "gbif.zip"
10+
},
11+
"conversion": {}
12+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from pathlib import Path
2+
import lib.downloading as dl
3+
from lib.secrets import secrets
4+
import requests
5+
6+
def collect(outputFilePath: Path) -> None:
7+
baseURL = "https://api.gbif.org/v1"
8+
requestEndpoint = "/occurrence/download/request"
9+
statusEndpoint = "/occurrence/download"
10+
11+
headers = {
12+
"Content-Type": "application/json"
13+
}
14+
15+
formData = {
16+
"creator": secrets.gbif.creator,
17+
"notificationAddresses": [
18+
secrets.general.email
19+
],
20+
"sendNotification": "false",
21+
"format": "SIMPLE_CSV",
22+
"predicate": {
23+
"type": "and",
24+
"predicates": [
25+
{
26+
"type": "in",
27+
"key": "BASIS_OF_RECORD",
28+
"values": [
29+
"MATERIAL_SAMPLE",
30+
"MATERIAL_CITATION",
31+
"PRESERVED_SPECIMEN",
32+
"FOSSIL_SPECIMEN",
33+
"LIVING_SPECIMEN",
34+
"OCCURRENCE"
35+
]
36+
},
37+
{
38+
"type": "equals",
39+
"key": "COUNTRY",
40+
"value": "AU"
41+
},
42+
{
43+
"type": "equals",
44+
"key": "HAS_COORDINATE",
45+
"value": "true"
46+
},
47+
{
48+
"type": "equals",
49+
"key": "HAS_GEOSPATIAL_ISSUE",
50+
"value": "false"
51+
},
52+
{
53+
"type": "equals",
54+
"key": "OCCURRENCE_STATUS",
55+
"value": "PRESENT"
56+
},
57+
]
58+
}
59+
}
60+
61+
strFormData = str(formData).replace(" ", "").replace("'", '"')
62+
response = requests.post(f"{baseURL}{requestEndpoint}", headers=headers, data=strFormData, auth=dl.buildAuth(secrets.general.email, secrets.gbif.password))
63+
requestID = response.text
64+
65+
statusURL = f"{baseURL}{statusEndpoint}/{requestID}"
66+
dl.asyncRunner(statusURL, "status", "SUCCEEDED", "downloadLink", outputFilePath)

0 commit comments

Comments
 (0)