164def time_range_args(params: "OnlineParams") -> dict[str, int]:
165 """Returns a dictionary with a time range arguments based on
166 ``params["time_range"]``.
168 Google Scholar supports a detailed search by year. Searching by *last
169 month* or *last week* (as offered by SearXNG) is uncommon for scientific
170 publications and is not supported by Google Scholar.
172 To limit the result list when the users selects a range, all the SearXNG
173 ranges (*day*, *week*, *month*, *year*) are mapped to *year*. If no range
174 is set an empty dictionary of arguments is returned.
176 Example; when user selects a time range and we find ourselves in the year
177 2025 (current year minus one):
184 ret_val: dict[str, int] = {}
185 if params["time_range"] in time_range_dict:
186 ret_val["as_ylo"] = datetime.now().year - 1
190def detect_google_captcha(dom: ElementType):
191 """In case of CAPTCHA Google Scholar open its own *not a Robot* dialog and is
192 not redirected to ``sorry.google.com``.
194 if eval_xpath(dom, "//form[@id='gs_captcha_f']"):
195 raise SearxEngineCaptchaException()
198def parse_gs_a(text: str | None) -> tuple[list[str], str, str, datetime | None]:
199 """Parse the text written in green.
202 * "{authors} - {journal}, {year} - {publisher}"
203 * "{authors} - {year} - {publisher}"
204 * "{authors} - {publisher}"
206 if text is None or text == "":
207 return [], "", "", None
209 s_text = text.split(" - ")
210 authors: list[str] = s_text[0].split(", ")
211 publisher: str = s_text[-1]
213 return authors, "", publisher, None
215 # the format is "{authors} - {journal}, {year} - {publisher}" or "{authors} - {year} - {publisher}"
216 # get journal and year
217 journal_year = s_text[1].split(", ")
218 # journal is optional and may contains some coma
219 if len(journal_year) > 1:
220 journal: str = ", ".join(journal_year[0:-1])
226 year = journal_year[-1]
228 publishedDate = datetime.strptime(year.strip(), "%Y")
231 return authors, journal, publisher, publishedDate