Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/downloads' into downloads
Browse files Browse the repository at this point in the history
# Conflicts:
#	pygbif/occurrences/__init__.py
  • Loading branch information
peterdesmet committed Jun 6, 2016
2 parents 4dac500 + 348f3bc commit 1a950d8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
8 changes: 5 additions & 3 deletions demos/pygbif-intro.ipynb
Expand Up @@ -284,7 +284,9 @@
"collapsed": true
},
"outputs": [],
"source": []
"source": [
""
]
}
],
"metadata": {
Expand All @@ -296,7 +298,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 2.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand All @@ -308,4 +310,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
2 changes: 1 addition & 1 deletion pygbif/__init__.py
Expand Up @@ -42,6 +42,6 @@
__license__ = 'MIT'

from .occurrences import search, get, count, download
from .species import names,name_parser
from .species import names, name_parser
from .registry import datasets, nodes
from .gbifissues import occ_issues_lookup
2 changes: 1 addition & 1 deletion pygbif/occurrences/__init__.py
Expand Up @@ -4,4 +4,4 @@
from .get import get, get_verbatim, get_fragment
from .count import count, count_basisofrecord, count_year, \
count_datasets, count_countries, count_schema, count_publishingcountries
from .download import download, download_meta, download_list, download_get
from .download import download, download_meta, download_list, download_get, GBIFDownload
32 changes: 24 additions & 8 deletions pygbif/occurrences/download.py
Expand Up @@ -129,7 +129,7 @@ def download(*args, user=None, pwd=None,
predicate['type'])

out = req.post_download(user, pwd)
return [out, user, email]
return (out, user, email)


class GBIFDownload(object):
Expand Down Expand Up @@ -167,6 +167,7 @@ def __init__(self, creator, email, polygon=None, main_pred_type='and'):
'predicates': self.predicates
}
}
self.request_id = None

# prepare the geometry polygon constructions
if polygon:
Expand Down Expand Up @@ -262,24 +263,39 @@ def add_geometry(self, polygon, geom_type='within'):
"""
self.predicates.append({'type': geom_type, 'geometry': polygon})

def post_download(self, user, pwd):
def post_download(self, user=None, pwd=None):
"""
:param user: Username
:param pwd: Password
:return:
"""
pprint.pprint(self.payload)
user = _check_environ('GBIF_USER', user)
pwd = _check_environ('GBIF_PWD', pwd)

#pprint.pprint(self.payload)
r = requests.post(self.url,
auth=auth.HTTPBasicAuth(user, pwd),
data=json.dumps(self.payload),
headers=self.header)

if r.status_code > 203:
raise Exception('error: ' + r.content)
if r.headers()['Content-Type'] == 'application/json':
raise Exception('not of type json')
return r.json()
raise Exception('error: ' + r.text +
', with error status code ' +
str(r.status_code) +
'check your number of active downloads.')
else:
self.request_id = r.text
print('Your download key is ', self.request_id)
return self.request_id

def get_status(self):
"""get the current download status"""
return get_download_status(self.request_id)


def get_download_status(request_key):
"""get the current download status"""
return download_meta(request_key).get('status')


def download_meta(key, **kwargs):
Expand Down

0 comments on commit 1a950d8

Please sign in to comment.