2021-04-12 19:47:21 +02:00
|
|
|
from typing import (
|
|
|
|
AsyncIterable,
|
|
|
|
Callable,
|
|
|
|
)
|
2021-01-08 21:08:47 +01:00
|
|
|
|
2021-04-12 19:47:21 +02:00
|
|
|
from library.logging import error_log
|
2021-01-08 21:08:47 +01:00
|
|
|
from nexus.pylon.sources.base import (
|
|
|
|
DoiSource,
|
|
|
|
PreparedRequest,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class NejmSource(DoiSource):
|
|
|
|
base_url = 'https://www.nejm.org'
|
|
|
|
resolve_timeout = 10
|
|
|
|
use_proxy = False
|
|
|
|
|
2021-04-12 19:47:21 +02:00
|
|
|
async def resolve(self, error_log_func: Callable = error_log) -> AsyncIterable[PreparedRequest]:
|
2021-01-08 21:08:47 +01:00
|
|
|
async with self.get_resolve_session() as session:
|
|
|
|
url = f'{self.base_url}/doi/pdf/{self.doi}'
|
2021-04-12 19:47:21 +02:00
|
|
|
async with PreparedRequest(
|
|
|
|
method='get',
|
|
|
|
url=url,
|
2021-04-09 10:17:38 +02:00
|
|
|
timeout=self.resolve_timeout,
|
2021-04-12 19:47:21 +02:00
|
|
|
).execute_with(session=session) as resp:
|
|
|
|
yield PreparedRequest(method='get', cookies=resp.cookies, url=str(resp.url), timeout=self.timeout)
|