diff --git a/papersurfer.py b/papersurfer.py index 426af5cf95fb11b383ef77ed048e42d0df3be597..94493a57b576e9d024d3454c1eebb52918b4f134 100644 --- a/papersurfer.py +++ b/papersurfer.py @@ -44,22 +44,11 @@ class PaperDTO: class Bibtex: - def entry(self, author, title, journal, year): - return BibliographyData({ - f'{author}{year}': Entry('article', [ - ('author', author), - ('title', title), - ('journal', journal), - ('year', year), - ]) - }).to_string('bibtex') - def entry_from_doi(self, doi): - paper = Doi().get_info(doi) - return self.entry(paper.author, paper.title, paper.journal, paper.year) + return Doi().get_bibtex(doi) def bib_from_dois(self, dois): - return "\n".join([self.entry_from_doi(doi) for doi in dois]) + return "\n".join([Doi().get_bibtex(doi) for doi in dois]) class Doi: @@ -86,6 +75,12 @@ class Doi: return PaperDTO(author, title, journal, year, doi) + def get_bibtex(self, doi): + headers = { + 'Accept': 'text/bibliography; style=bibtex', + } + return requests.get(f'http://dx.doi.org/{doi}', headers=headers).text + def get_info(self, doi): xml = self.load_doi_data(doi) return self.parse_doi_xml(xml)