def bst_openaire_altmetric(): """ """ recids = search_pattern(p="0->Z", f="0247_a") a = Altmetric() for recid in recids: try: # Check if we already have an Altmetric id sysno_inst = get_fieldvalues(recid, "035__9") if ['Altmetric'] in sysno_inst: continue doi_val = get_fieldvalues(recid, "0247_a")[0] json_res = a.doi(doi_val) rec = {} record_add_field(rec, "001", controlfield_value=str(recid)) if json_res: record_add_field(rec, '035', subfields=[('a', str(json_res['altmetric_id'])), ('9', 'Altmetric')]) bibupload(rec, opt_mode='correct') except AltmetricHTTPException, e: register_exception(prefix='Altmetric error (status code %s): %s' % (e.status_code, str(e)), alert_admin=False)
def bst_openaire_altmetric(): """ """ recids = search_pattern(p="0->Z", f="0247_a") a = Altmetric() for recid in recids: try: # Check if we already have an Altmetric id sysno_inst = get_fieldvalues(recid, "035__9") if ['Altmetric'] in sysno_inst: continue doi_val = get_fieldvalues(recid, "0247_a")[0] json_res = a.doi(doi_val) rec = {} record_add_field(rec, "001", controlfield_value=str(recid)) if json_res: record_add_field(rec, '035', subfields=[('a', str(json_res['altmetric_id'])), ('9', 'Altmetric')]) bibupload(rec, opt_mode='correct') except AltmetricHTTPException, e: register_exception(prefix='Altmetric error (status code %s): %s' % (e.status_code, str(e)), alert_admin=False)
def openaire_altmetric_update(recids, upload=True): """ Retrieve Altmetric information for a record. """ logger.debug("Checking Altmetric for recids %s" % recids) a = Altmetric() records = [] for recid in recids: logger.debug("Checking Altmetric for recid %s" % recid) try: # Check if we already have an Altmetric id sysno_inst = get_fieldvalues(recid, "035__9") if ['Altmetric'] in sysno_inst: continue doi_val = get_fieldvalues(recid, "0247_a")[0] logger.debug("Found DOI %s" % doi_val) json_res = a.doi(doi_val) logger.debug("Altmetric response: %s" % json_res) rec = {} record_add_field(rec, "001", controlfield_value=str(recid)) if json_res: record_add_field(rec, '035', subfields=[('a', str(json_res['altmetric_id'])), ('9', 'Altmetric')]) records.append(rec) except AltmetricHTTPException as e: logger.warning( 'Altmetric error for recid %s with DOI %s (status code %s): %s' % (recid, doi_val, e.status_code, str(e))) register_exception(prefix='Altmetric error (status code %s): %s' % (e.status_code, str(e)), alert_admin=False) except IndexError: logger.debug("No DOI found") pass if upload and records: if len(records) == 1: bibupload(record=records[0], file_prefix="altmetric") else: bibupload(collection=records, file_prefix="altmetric") return records
def getAltScore(inputDF): """This function reads in an already existing dataframe, typically the one obtained from the searchPubMed function. It returns said dataframe with an additional column, giving the Altmetric score for a given article DOI in the table according to Altmetrics. Parameters: inputDF(Pandas.DataFrame): this is a Pandas dataframe with PubMed ID as indices, and a column labelled "DOI" with all the DOIs for the associated PubMed ID. Returns: Pandas.DataFrame, identical to input with addition of column "Altmetric Score," giving the Altmetric score, calculated by Altmetrics, for a given article. Example: queryDF = getAltScore(queryDF)""" #First gather the DOI for each article in the dataframe. doiList = inputDF["DOI"].tolist() listAltScore = [] count = 1 print("Getting Altmetrics Score") #Now for every DOI, use CrossRef to find the associated Altmetrics score. for entry in doiList: print(count) try: if entry != "": a = Altmetric() thisDOI = a.doi(entry) extractScore = thisDOI["score"] listAltScore.append(extractScore) else: listAltScore.append(None) except: listAltScore.append(None) count = count + 1 #Now add a column of Altmetrics scores to the dataframe. inputDF["Altmetric Score"] = listAltScore print("Altmetrics Search Complete!") return inputDF
def openaire_altmetric_update(recids, upload=True): """ Retrieve Altmetric information for a record. """ logger.debug("Checking Altmetric for recids %s" % recids) a = Altmetric() records = [] for recid in recids: logger.debug("Checking Altmetric for recid %s" % recid) try: # Check if we already have an Altmetric id sysno_inst = get_fieldvalues(recid, "035__9") if ["Altmetric"] in sysno_inst: continue doi_val = get_fieldvalues(recid, "0247_a")[0] logger.debug("Found DOI %s" % doi_val) json_res = a.doi(doi_val) logger.debug("Altmetric response: %s" % json_res) rec = {} record_add_field(rec, "001", controlfield_value=str(recid)) if json_res: record_add_field(rec, "035", subfields=[("a", str(json_res["altmetric_id"])), ("9", "Altmetric")]) records.append(rec) except AltmetricHTTPException as e: logger.warning( "Altmetric error for recid %s with DOI %s (status code %s): %s" % (recid, doi_val, e.status_code, str(e)) ) register_exception( prefix="Altmetric error (status code %s): %s" % (e.status_code, str(e)), alert_admin=False ) except IndexError: logger.debug("No DOI found") pass if upload and records: if len(records) == 1: bibupload(record=records[0], file_prefix="altmetric") else: bibupload(collection=records, file_prefix="altmetric") return records
def openaire_altmetric_update(recids, upload=True): """ Retrieve Altmetric information for a record. """ logger.debug("Checking Altmetric for recids %s" % recids) a = Altmetric() records = [] for recid in recids: logger.debug("Checking Altmetric for recid %s" % recid) try: # Check if we already have an Altmetric id sysno_inst = get_fieldvalues(recid, "035__9") if ['Altmetric'] in sysno_inst: continue doi_val = get_fieldvalues(recid, "0247_a")[0] logger.debug("Found DOI %s" % doi_val) json_res = a.doi(doi_val) logger.debug("Altmetric response: %s" % json_res) rec = {} record_add_field(rec, "001", controlfield_value=str(recid)) if json_res: record_add_field(rec, '035', subfields=[ ('a', str(json_res['altmetric_id'])), ('9', 'Altmetric') ]) records.append(rec) except AltmetricHTTPException, e: logger.warning( 'Altmetric error for recid %s with DOI %s (status code %s): %s' % (recid, doi_val, e.status_code, str(e)) ) register_exception( prefix='Altmetric error (status code %s): %s' % ( e.status_code, str(e)), alert_admin=False ) except IndexError: logger.debug("No DOI found") pass
def update(self): rsp = None a = Altmetric(settings.ALTMETRIC_API_KEY) ids = self.paper.get_ids() # Fetch altmetric data based on paper supported id try: if 'doi' in ids: rsp = a.doi(ids.get('doi', '')) if not rsp and 'arx' in ids: rsp = a.arxiv(ids.get('arx')) if not rsp and 'pmi' in ids: rsp = a.pmid(ids.get('pmi')) except AltmetricHTTPException: raise # Parse json if rsp: self.score = rsp.get('score') self.altmetric_id = rsp.get('altmetric_id') self.altmetric_jid = rsp.get('altmetric_jid', '') self.score_1d = rsp.get('history').get('1d') self.score_2d = rsp.get('history').get('2d') self.score_3d = rsp.get('history').get('3d') self.score_4d = rsp.get('history').get('4d') self.score_5d = rsp.get('history').get('5d') self.score_6d = rsp.get('history').get('6d') self.score_1w = rsp.get('history').get('1w') self.score_1m = rsp.get('history').get('1m') self.score_3m = rsp.get('history').get('3m') self.score_6m = rsp.get('history').get('6m') self.score_1y = rsp.get('history').get('1y') self.cited_by_posts_count = rsp.get('cited_by_posts_count', 0) self.cited_by_delicious_count = rsp.get('cited_by_delicious_count', 0) self.cited_by_fbwalls_count = rsp.get('cited_by_fbwalss_count', 0) self.cited_by_feeds_count = rsp.get('cited_by_feeds_count', 0) self.cited_by_forum_count = rsp.get('cited_by_forum_count', 0) self.cited_by_gplus_count = rsp.get('cited_by_gplus_count', 0) self.cited_by_linkedin_count = rsp.get('cited_by_linkedin_count', 0) self.cited_by_msm_count = rsp.get('cited_by_msm_count', 0) self.cited_by_peer_review_sites_count = rsp.get( 'cited_by_peer_review_sites_count', 0) self.cited_by_pinners_count = rsp.get('cited_by_pinners_count', 0) self.cited_by_policies_count = rsp.get('cited_by_policies_count', 0) self.cited_by_qs_count = rsp.get('cited_by_qs_count', 0) self.cited_by_rdts_count = rsp.get('cited_by_rdts_count', 0) self.cited_by_rh_count = rsp.get('cited_by_rh_count', 0) self.cited_by_tweeters_count = rsp.get('cited_by_tweeters_count', 0) self.cited_by_videos_count = rsp.get('cited_by_videos_count', 0) self.cited_by_weibo_count = rsp.get('cited_by_weibo_count', 0) self.cited_by_wikipedia_count = rsp.get('cited_by_wikipedia_count', 0) if isinstance(rsp.get('readers'), dict): self.readers_citeulike = rsp.get('readers').get('citeulike') self.readers_mendeley = rsp.get('readers').get('mendeley') self.image = rsp.get('images').get('small') match = re.findall(r'types=(P?[\w]+)', self.image) if match: self.type = match[0] # save self.save()