diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-08-19 18:42:56 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-08-19 18:42:56 +0100 |
| commit | 129e8c597810848f98121b3b2ca522c83528ca1c (patch) | |
| tree | 95099b71a879d17d9ce2b98aa5b55acf94a78a12 | |
| parent | Move all regexes to class variables and simplify validate (diff) | |
| download | paper2remarkable-129e8c597810848f98121b3b2ca522c83528ca1c.tar.gz paper2remarkable-129e8c597810848f98121b3b2ca522c83528ca1c.zip | |
Move retrieve_pdf to Provider class
| -rwxr-xr-x | arxiv2remarkable.py | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index bae95f3..96ba71c 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -98,9 +98,10 @@ class Provider(metaclass=abc.ABCMeta): def validate(src): """ Validate whether ``src`` is appropriate for this provider """ - @abc.abstractmethod def retrieve_pdf(self, src, filename): """ Download pdf from src and save to filename """ + _, pdf_url = self.get_abs_pdf_urls(src) + self.download_url(pdf_url, filename) def _format_authors(self, soup_authors, sep=",", idx=0, op=None): op = (lambda x: x) if op is None else op @@ -401,11 +402,6 @@ class Arxiv(Provider): """Check if the url is to an arXiv page. """ return re.match(Arxiv.re_abs, src) or re.match(Arxiv.re_pdf, src) - def retrieve_pdf(self, src, filename): - """ Download the file and save as filename """ - _, pdf_url = self.get_abs_pdf_urls(src) - self.download_url(pdf_url, filename) - class Pubmed(Provider): @@ -435,10 +431,6 @@ class Pubmed(Provider): def validate(src): return re.match(Pubmed.re_abs, src) or re.match(Pubmed.re_pdf, src) - def retrieve_pdf(self, src, filename): - _, pdf_url = self.get_abs_pdf_urls(src) - self.download_url(pdf_url, filename) - def _format_authors(self, soup_authors): op = lambda x: x[0].split(",") return super()._format_authors(soup_authors, sep=" ", idx=-1, op=op) @@ -489,10 +481,6 @@ class ACM(Provider): ) return abs_url, pdf_url - def retrieve_pdf(self, src, filename): - _, pdf_url = self.get_abs_pdf_urls(src) - self.download_url(pdf_url, filename) - def validate(src): m = re.fullmatch(ACM.re_abs, src) return not m is None @@ -538,11 +526,6 @@ class OpenReview(Provider): OpenReview.re_pdf, src ) - def retrieve_pdf(self, src, filename): - """ Download the file and save as filename """ - _, pdf_url = self.get_abs_pdf_urls(src) - self.download_url(pdf_url, filename) - def _format_authors(self, soup_authors): return super()._format_authors(soup_authors, sep=" ", idx=-1) @@ -572,10 +555,6 @@ class Springer(Provider): def validate(src): return re.match(Springer.re_abs, src) or re.match(Springer.re_pdf, src) - def retrieve_pdf(self, src, filename): - _, pdf_url = self.get_abs_pdf_urls(src) - self.download_url(pdf_url, filename) - def _format_authors(self, soup_authors): return super()._format_authors(soup_authors, sep=" ", idx=-1) |
