Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gbif/pygbif into v0.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
John Waller committed Oct 28, 2024
2 parents 9942578 + 57676c9 commit 680f0ff
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 45 deletions.
4 changes: 2 additions & 2 deletions pygbif/occurrences/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
download_get,
download_cancel,
download_describe,
download_sql
download_sql,
download_citation
)
from .citation import citation
24 changes: 0 additions & 24 deletions pygbif/occurrences/citation.py

This file was deleted.

25 changes: 24 additions & 1 deletion pygbif/occurrences/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
gbif_GET,
gbif_GET_write,
gbif_DELETE,
gbif_baseurl
gbif_baseurl,
gbif_GET_raw
)


Expand Down Expand Up @@ -723,6 +724,28 @@ def download_sql(sql,
logging.info("Your sql download key is " + request_id)
return request_id

def download_citation(key):
"""
Get citation from a download key
:param key: [int] A GBIF download key
:return: A dictionary, of results
Usage::
from pygbif import occurrences
occurrences.download_citation("0235283-220831081235567")
"""
url = gbif_baseurl + "occurrence/download/" + str(key) + "/citation"
if re.fullmatch(r'^\d+-\d+$', key):
out = gbif_GET_raw(url).decode('utf-8')
return(out)
else:
raise ValueError("key must be a GBIF download key")


operators = [
"equals",
"and",
Expand Down
15 changes: 0 additions & 15 deletions test/test-occurrences-citation.py

This file was deleted.

15 changes: 15 additions & 0 deletions test/test-occurrences-download_citation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pygbif import occurrences as occ
import vcr

@vcr.use_cassette('test/vcr_cassettes/test-occurrences-download_citation.yaml')
def test_download_citation():
res=occ.download_citation("0235283-220831081235567")
assert "str" == res.__class__.__name__
"GBIF.org (2 January 2023) GBIF Occurrence Download https://doi.org/10.15468/dl.29wbtx" == res

def test_download_citation_failswell():
try:
occ.download_citation("dog")
except ValueError as e:
assert str(e) == "key must be a GBIF download key"

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interactions:
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
- python-requests/2.32.3
method: GET
uri: https://api.gbif.org/v1/occurrence/download/0235283-220831081235567/citation
response:
Expand All @@ -31,7 +31,7 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 04 Oct 2024 06:59:59 GMT
- Fri, 04 Oct 2024 09:38:11 GMT
Expires:
- '0'
Pragma:
Expand All @@ -45,7 +45,7 @@ interactions:
X-Frame-Options:
- DENY
X-Varnish:
- '658835659'
- '851347368'
X-XSS-Protection:
- 1; mode=block
status:
Expand Down

0 comments on commit 680f0ff

Please sign in to comment.