How to use the wikidataintegrator.wdi_config.config function in wikidataintegrator

To help you get started, we’ve selected a few wikidataintegrator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SuLab / WikidataIntegrator / wikidataintegrator / wdi_login.py View on Github external
self.s = requests.Session()
        self.edit_token = ''
        self.instantiation_time = time.time()
        self.token_renew_period = token_renew_period

        self.mw_url = "https://www.mediawiki.org/w/index.php"
        self.consumer_key = consumer_key
        self.consumer_secret = consumer_secret
        self.response_qs = None
        self.callback_url = callback_url

        if user_agent:
            self.user_agent = user_agent
        else:
            # if a user is given append " (User:USER)" to the UA string and update that value in CONFIG
            if user and user.lower() not in config['USER_AGENT_DEFAULT'].lower():
                config['USER_AGENT_DEFAULT'] += " (User:{})".format(user)
            self.user_agent = config['USER_AGENT_DEFAULT']
        self.s.headers.update({
            'User-Agent': self.user_agent
        })

        if self.consumer_key and self.consumer_secret:
            # Oauth procedure, based on https://www.mediawiki.org/wiki/OAuth/For_Developers

            # Consruct a "consumer" from the key/secret provided by MediaWiki
            self.consumer_token = ConsumerToken(self.consumer_key, self.consumer_secret)

            # Construct handshaker with wiki URI and consumer
            self.handshaker = Handshaker(self.mw_url, self.consumer_token, callback=self.callback_url,
                                         user_agent=self.user_agent)
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_helpers / publication.py View on Github external
# https://europepmc.org/docs/EBI_Europe_PMC_Web_Service_Reference.pdf
    assert id_type in Publication.ID_TYPES, "id_type must be in {}".format(Publication.ID_TYPES.keys())
    # Request the data
    if id_type == "pmcid":
        url = 'https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=PMCID:PMC{}&resulttype=core&format=json'
        url = url.format(ext_id)
    elif id_type == "doi":
        url = "https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=DOI:%22{}%22&resulttype=core&format=json"
        url = url.format(ext_id)
    elif id_type == "pmid":
        url = 'https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=EXT_ID:{}%20AND%20SRC:MED&resulttype=core&format=json'
        url = url.format(ext_id, id_type)
    else:
        raise ValueError("id_type must be in {}".format(Publication.ID_TYPES.keys()))
    headers = {
        'User-Agent': config['USER_AGENT_DEFAULT']
    }
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    d = response.json()
    if d['hitCount'] != 1:
        raise ValueError("No results")
    article = d['resultList']['result'][0]

    p = Publication()
    p.ref_url = url
    p.source = "europepmc"
    original_title = article['title']
    # to remove trailing dot
    # to exclude '...' and abbreviations such as U.S.A.
    p.title = original_title
    if original_title[-1] == '.' and original_title[-3] != '.':
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
def __init__(self, wd_item_id='', new_item=False, data=None,
                 mediawiki_api_url='https://www.wikidata.org/w/api.php',
                 sparql_endpoint_url='https://query.wikidata.org/sparql',
                 append_value=None, fast_run=False, fast_run_base_filter=None, fast_run_use_refs=False,
                 ref_handler=None, global_ref_mode='KEEP_GOOD', good_refs=None, keep_good_ref_statements=False,
                 search_only=False, item_data=None, user_agent=config['USER_AGENT_DEFAULT'],
                 core_props=None, core_prop_match_thresh=0.66):
        """
        constructor
        :param wd_item_id: Wikidata item id
        :param new_item: This parameter lets the user indicate if a new item should be created
        :type new_item: True or False
        :param data: a dictionary with WD property strings as keys and the data which should be written to
            a WD item as the property values
        :type data: List[WDBaseDataType]
        :param append_value: a list of properties where potential existing values should not be overwritten by the data
            passed in the :parameter data.
        :type append_value: list of property number strings
        :param fast_run: True if this item should be run in fastrun mode, otherwise False. User setting this to True
            should also specify the fast_run_base_filter for these item types
        :type fast_run: bool
        :param fast_run_base_filter: A property value dict determining the Wikidata property and the corresponding value
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_helpers.py View on Github external
'type': None,
            'date': None,
            'pages': None,
            'authors': None,
            'pubtypes': None,
            'pubtype_qid': None,
            'parsed': False
        }
        if self.id_type == "PMC" and self.ext_id.startswith("PMC"):
            self.ext_id = self.ext_id.replace("PMC", "")

        self.reference = None
        self.statements = None
        self.wdid = None
        self.article = None
        self.user_agent = config['USER_AGENT_DEFAULT']