diff options
Diffstat (limited to 's2.py')
| -rw-r--r-- | s2.py | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -138,6 +138,22 @@ class SemanticScholarAPI(object): return size @staticmethod + def fetch_doi(url, fn, **kwargs): + try: + resp = requests.get(url, params=kwargs, headers=SemanticScholarAPI.headers, verify=False) + if resp.status_code != 200: + return None + except: + return None + size = 0 + with open(fn, 'wb') as f: + for chunk in resp.iter_content(chunk_size=1024): + if chunk: + size += len(chunk) + f.write(chunk) + return size, response.url + + @staticmethod def paper(paper_id, **kwargs): url = "{}/{}".format(SemanticScholarAPI.PAPER_ENDPOINT, paper_id) resp = requests.get(url, params=kwargs, headers=SemanticScholarAPI.headers) |
