File size: 922 Bytes
d195d4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import yaml

from scholarly import scholarly
from scholarly import ProxyGenerator
import os

from factool.env_config import factool_env_config

# env
# scraper_api_key = factool_env_config.scraper_api_key

class google_scholar():
    def __init__(self):
        pg = ProxyGenerator()
        scraper_api_key = os.environ.get("SCRAPER_API_KEY", None)
        assert scraper_api_key is not None, "Please set the SCRAPER_API_KEY environment variable."
        success = pg.ScraperAPI(scraper_api_key)
        scholarly.use_proxy(pg)

    def run(self, query):
        try:
            results = scholarly.search_pubs(query)
            paper_info = next(results)
            paper_info_subset = {key: paper_info['bib'][key] for key in ['title', 'author', 'pub_year']}
            return paper_info_subset
        except StopIteration:
            return {'title': "no match!", "author": "no match!", "pub_year": "no match!"}