예제 #1
0
def get_folder(api, view):
    """Auxiliary function to get the cache folder belonging to an API,
    eventually create the folder.
    """
    from configparser import NoOptionError
    from pathlib import Path

    from pybliometrics.scopus.utils import CONFIG_FILE, DEFAULT_PATHS
    from pybliometrics.scopus.utils.create_config import create_config

    if not config.has_section('Directories'):
        create_config()
    try:
        parent = Path(config.get('Directories', api))
    except NoOptionError:
        parent = DEFAULT_PATHS[api]
        config.set('Directories', api, str(parent))
        with open(CONFIG_FILE, 'w') as ouf:
            config.write(ouf)
    try:
        folder = parent/view
    except TypeError:
        folder = parent
    folder.mkdir(parents=True, exist_ok=True)
    return folder
예제 #2
0
def get_folder(api, view):
    """Auxiliary function to get the cache folder belonging to a an API
    and eventually create the folder.
    """
    if not config.has_section('Directories'):
        create_config()
    try:
        folder = config.get('Directories', api)
    except NoOptionError:
        folder = DEFAULT_PATHS[api]
    folder = os.path.join(folder, view or '')
    if not os.path.exists(folder):
        os.makedirs(folder)
    return folder
예제 #3
0
def get_folder(api, view):
    """Auxiliary function to get the cache folder belonging to an API,
    eventually create the folder.
    """
    if not config.has_section('Directories'):
        create_config()
    try:
        folder = config.get('Directories', api)
    except NoOptionError:
        folder = DEFAULT_PATHS[api]
        config.set('Directories', api, folder)
        with open(CONFIG_FILE, 'w') as f:
            config.write(f)
    folder = os.path.join(folder, view or '')
    if not os.path.exists(folder):
        os.makedirs(folder)
    return folder
예제 #4
0
import configparser
from collections import deque
from pathlib import Path

from pybliometrics.scopus.utils.constants import CONFIG_FILE, RATELIMITS
from pybliometrics.scopus.utils.create_config import create_config

# Read/create config file (with fixture for RTFD.io)
config = configparser.ConfigParser()
config.optionxform = str
try:
    if not CONFIG_FILE.exists():
        config = create_config()
    else:
        config.read(CONFIG_FILE)
    KEYS = [
        k.strip() for k in config.get('Authentication', 'APIKey').split(",")
    ]
except EOFError:
    pass

# Throttling params
_throttling_params = {k: deque(maxlen=v) for k, v in RATELIMITS.items()}