mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-21 09:07:46 +01:00
9ce67ec590
- feat(idm): Rename IDM-2 to IDM - feat(idm): Open IDM 3 internal commit(s) GitOrigin-RevId: e302e9b5cda18cca1adc4ae8a3d906714d222106
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from typing import (
|
|
AsyncIterable,
|
|
Callable,
|
|
)
|
|
|
|
from library.logging import error_log
|
|
from nexus.pylon.sources.base import (
|
|
DoiSource,
|
|
PreparedRequest,
|
|
)
|
|
|
|
|
|
class LancetSource(DoiSource):
|
|
base_url = 'https://www.thelancet.com'
|
|
resolve_timeout = 10
|
|
use_proxy = False
|
|
|
|
async def resolve(self, error_log_func: Callable = error_log) -> AsyncIterable[PreparedRequest]:
|
|
async with self.get_resolve_session() as session:
|
|
splitted_doi = self.doi.split("/", maxsplit=1)
|
|
if len(splitted_doi) < 2:
|
|
return
|
|
url = f'{self.base_url}/action/showPdf?pii={splitted_doi[1].upper()}'
|
|
async with PreparedRequest(
|
|
method='get',
|
|
url=url,
|
|
timeout=self.resolve_timeout,
|
|
).execute_with(session=session) as resp:
|
|
yield PreparedRequest(
|
|
method='get',
|
|
cookies=resp.cookies,
|
|
url=str(resp.url),
|
|
timeout=self.resolve_timeout,
|
|
)
|