|
16 | 16 | _KEYWORDSEARCH = '/citations?hl=en&view_op=search_authors&mauthors=label:{0}' |
17 | 17 | _KEYWORDSEARCHBASE = '/citations?hl=en&view_op=search_authors&mauthors={}' |
18 | 18 | _PUBSEARCH = '/scholar?hl=en&q={0}' |
| 19 | +_CITEDBYSEARCH = '/scholar?hl=en&cites={0}' |
19 | 20 |
|
20 | 21 |
|
21 | 22 | class _Scholarly: |
@@ -123,29 +124,18 @@ def search_pubs(self, |
123 | 124 | 'url_scholarbib': '/scholar?q=info:K8ZpoI6hZNoJ:scholar.google.com/&output=cite&scirp=0&hl=en'} |
124 | 125 |
|
125 | 126 | """ |
126 | | - url = _PUBSEARCH.format(requests.utils.quote(query)) |
127 | | - |
128 | | - yr_lo = '&as_ylo={0}'.format(year_low) if year_low is not None else '' |
129 | | - yr_hi = '&as_yhi={0}'.format(year_high) if year_high is not None else '' |
130 | | - citations = '&as_vis={0}'.format(1 - int(citations)) |
131 | | - patents = '&as_sdt={0},33'.format(1 - int(patents)) |
132 | | - sortby = '' |
133 | | - start = '&start={0}'.format(start_index) if start_index > 0 else '' |
134 | | - |
135 | | - if sort_by == "date": |
136 | | - if include_last_year == "abstracts": |
137 | | - sortby = '&scisbd=1' |
138 | | - elif include_last_year == "everything": |
139 | | - sortby = '&scisbd=2' |
140 | | - else: |
141 | | - print("Invalid option for 'include_last_year', available options: 'everything', 'abstracts'") |
142 | | - return |
143 | | - elif sort_by != "relevance": |
144 | | - print("Invalid option for 'sort_by', available options: 'relevance', 'date'") |
145 | | - return |
146 | | - |
147 | | - # improve str below |
148 | | - url = url + yr_lo + yr_hi + citations + patents + sortby + start |
| 127 | + url = _construct_url(_PUBSEARCH.format(requests.utils.quote(query)), patents=patents, citations=citations, year_low=year_low, year_high=year_high) |
| 128 | + return self.__nav.search_publications(url) |
| 129 | + |
| 130 | + def search_citedby(self, publication_id: int, **kwargs): |
| 131 | + """Searches by Google Scholar publication id and returns a generator of Publication objects. |
| 132 | +
|
| 133 | + :param publication_id: Google Scholar publication id |
| 134 | + :type publication_id: int |
| 135 | +
|
| 136 | + For the remaining parameters, see documentation of `search_pubs`. |
| 137 | + """ |
| 138 | + url = _construct_url(_CITEDBYSEARCH.format(str(publication_id)), **kwargs) |
149 | 139 | return self.__nav.search_publications(url) |
150 | 140 |
|
151 | 141 | def search_single_pub(self, pub_title: str, filled: bool = False)->PublicationParser: |
@@ -430,3 +420,33 @@ def search_org(self, name: str, fromauthor: bool = False) -> list: |
430 | 420 |
|
431 | 421 | url = _AUTHSEARCH.format(requests.utils.quote(name)) |
432 | 422 | return self.__nav.search_organization(url, fromauthor) |
| 423 | + |
| 424 | +def _construct_url(baseurl: str, patents: bool = True, |
| 425 | + citations: bool = True, year_low: int = None, |
| 426 | + year_high: int = None, sort_by: str = "relevance", |
| 427 | + include_last_year: str = "abstracts", |
| 428 | + start_index: int = 0)-> str: |
| 429 | + """Construct URL from requested parameters.""" |
| 430 | + url = baseurl |
| 431 | + |
| 432 | + yr_lo = '&as_ylo={0}'.format(year_low) if year_low is not None else '' |
| 433 | + yr_hi = '&as_yhi={0}'.format(year_high) if year_high is not None else '' |
| 434 | + citations = '&as_vis={0}'.format(1 - int(citations)) |
| 435 | + patents = '&as_sdt={0},33'.format(1 - int(patents)) |
| 436 | + sortby = '' |
| 437 | + start = '&start={0}'.format(start_index) if start_index > 0 else '' |
| 438 | + |
| 439 | + if sort_by == "date": |
| 440 | + if include_last_year == "abstracts": |
| 441 | + sortby = '&scisbd=1' |
| 442 | + elif include_last_year == "everything": |
| 443 | + sortby = '&scisbd=2' |
| 444 | + else: |
| 445 | + print("Invalid option for 'include_last_year', available options: 'everything', 'abstracts'") |
| 446 | + return |
| 447 | + elif sort_by != "relevance": |
| 448 | + print("Invalid option for 'sort_by', available options: 'relevance', 'date'") |
| 449 | + return |
| 450 | + |
| 451 | + # improve str below |
| 452 | + return url + yr_lo + yr_hi + citations + patents + sortby + start |
0 commit comments