Created
April 30, 2020 20:33
-
-
Save madhead/377781c50b770af562045c7f23952acd to your computer and use it in GitHub Desktop.
springer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import csv | |
import requests | |
from pathlib import Path | |
if __name__ == '__main__': | |
with open(sys.argv[1]) as csv_file: | |
csv = csv.DictReader(csv_file, delimiter=",", quoting=csv.QUOTE_ALL) | |
next(csv) | |
for row in csv: | |
print(f'Processing {row["Item Title"]} by {row["Authors"]}') | |
try: | |
print("Downloading PDF") | |
url = f'https://link.springer.com/content/pdf/{row["Item DOI"]}.pdf' | |
content = requests.get(url) | |
if len(content.content) < 500: | |
raise Exception("Not a PDF") | |
open(f'{Path(sys.argv[1]).parent}/{row["Item Title"]} - {row["Authors"]}.pdf', 'wb').write(content.content) | |
except: | |
print(f'Failed to download PDF for {row["Item Title"]} by {row["Authors"]}') | |
try: | |
print("Downloading EPUB") | |
url = f'https://link.springer.com/download/epub/{row["Item DOI"]}.epub' | |
content = requests.get(url) | |
if len(content.content) < 500: | |
raise Exception("Not a EPUB") | |
open(f'{Path(sys.argv[1]).parent}/{row["Item Title"]} - {row["Authors"]}.epub', 'wb').write(content.content) | |
except: | |
print(f'Failed to download EPUB for {row["Item Title"]} by {row["Authors"]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improved version: https://gist.github.com/CrazyCoder/2e2788c1542b93869c8b31948cde198a
:
and other special chars will fail on Windows)