예제 #1
0
class AltmetricUpdate:
    QUERY_INTERVAL_SEC = 0.0

    def __init__(self, api_key):
        self.altmetric = Altmetric(api_key=api_key)
        self.last_query = None

    def update(self, paper):
        if self.last_query:
            elapsed_time_sec = time.time() - self.last_query
            if self.QUERY_INTERVAL_SEC > 0.0 and elapsed_time_sec < self.QUERY_INTERVAL_SEC:
                time.sleep(int(ceil(self.QUERY_INTERVAL_SEC - elapsed_time_sec)))

        if paper.data_source_value == DataSource.ARXIV:
            data = self.altmetric.arxiv(paper.doi[6:])
        else:
            data = self.altmetric.doi(paper.doi)

        self.last_query = time.time()

        if data and data['score'] > 0.0:
            if not paper.altmetric_data:
                paper.altmetric_data = AltmetricData.objects.create()

            paper.altmetric_data.score = data['score']
            paper.altmetric_data.score_d = data['history']['1d']
            paper.altmetric_data.score_w = data['history']['1w']
            paper.altmetric_data.score_1m = data['history']['1m']
            paper.altmetric_data.score_3m = data['history']['3m']
            paper.altmetric_data.score_6m = data['history']['6m']
            paper.altmetric_data.score_y = data['history']['1y']
            paper.altmetric_data.save()

        paper.last_altmetric_update = timezone.now()
        paper.save()
예제 #2
0
    def update(self):
        print("Pulling questions from RM site...")
        data = {
            get_qid(q): {
                'doi': get_doi(q)
            }
            for q in Bot(api_key=API_KEY).get_citation_questions()
        }
        print("Done!\n")

        if 'alt' in self.services:
            print("Pulling data from altmetrics...")

            for i, (qid, paper) in enumerate(data.items()):
                print(f"Paper {i+1} of {len(data)}...")
                data[qid]['mendeley'] = int(Altmetric().article_from_doi(
                    paper["doi"]).readers['mendeley'])

            print("Done!\n")

        if 'scite' in self.services:
            pass

        self._data = data
        self.save()
예제 #3
0
# fetch_multiple_doi.py
#
# This example shows how to use pyAltmetric to make multiple calls for
# citations using a list of DOIs (Digital Object Identifier).
#
from pyaltmetric import Altmetric, Citation
import json

# list of target DOIs
dois = ('10.1038/news.2011.49', '10.1038/nj7361-479a', '10.1136/bmj.c6801',
        '10.1038/nature.2014.14583', '10.1038/news.2011.498')

# initialize an Altmetric instance
a = Altmetric()

# iterate through DOIs fetching each citation from api.altmetric.com
citations = map(a.doi, dois)

# write citation objects as json to a file
with open('citations_as_json.txt', 'w+') as outfile:
    json.dump(citations, outfile)
def get_altmetric(thisdoi):
    a = Altmetric()
    alt = a.doi(thisdoi.split("doi.org/")[1])
    return int(alt["score"])
예제 #5
0
from pyaltmetric import Altmetric, Citation, HTTPException
import csv

# initialize Altmetric
a = Altmetric()

with open('doi.list', 'r') as infile:
    with open('results.csv', 'w') as outfile:
        writer = csv.writer(outfile)

        for x in infile:
            x = x.rstrip() 
            # search for article using doi
            c = a.doi(x)
            if c:
                # initialize Citation and fetch fields
                citation = Citation(c)
                result = citation.get_fields('title', 'doi', 'journal',
                            'cited_by_posts_count', 'cited_by_tweeters_count',
                            'cited_by_fbwalls_count', 'cited_by_gplus_count',
                            'cited_by_rdts_count', 'cited_by_feeds_count')
            else:
                result = [x, 'no data']
            # write row to file 
            writer.writerow(result)

예제 #6
0
#Altmetric.com asks users not to hammer the server. If needed, add a delay to the API-calls. 
#Packages:
from pyaltmetric import Altmetric, Citation, HTTPException
import csv

# initialize Altmetric
a = Altmetric()

with open('Name of CSV-file with DOIs', 'r') as infile:
    with open('Name of file with results', 'w') as outfile:
        writer = csv.writer(outfile)

        for x in infile:
            x = x.rstrip()
            # search for article using doi
            c = a.doi(x)
            if c:
                # initialize Citation and fetch fields
                citation = Citation(c)
                result = citation.get_fields('doi','title','cited_by_msm_count') #Choose which data to retrieve msm=news media. 
            else:
                result = [x, 'no data'] #No data = DOI not found. 
            # write row to file
            writer.writerow(result)
예제 #7
0
 def __init__(self, api_key):
     self.altmetric = Altmetric(api_key=api_key)
     self.last_query = None
예제 #8
0
def altmetric(pmids):
    a = Altmetric()
    url = 'http://api.altmetric.com/v1/id/'
    #pmids = [pmids[i:i+900] for i in range(0, len(pmids), 900)]
    # initialize the altmetric dataframe so it can be appended by the loop
    altmet_df = pd.DataFrame(columns=[
        'title', 'doi', 'pmid', 'pmc', 'ads_id', 'isbns', 'altmetric_jid',
        'issns', 'journal', 'cohorts', 'abstract', 'context', 'authors',
        'type', 'handles', 'altmetric_id', 'schema', 'is_oa',
        'cited_by_posts_count', 'cited_by_tweeters_count',
        'cited_by_accounts_count', 'last_updated', 'score', 'history', 'url',
        'added_on', 'published_on', 'subjects', 'readers', 'readers_count',
        'images', 'details_url', 'uri', 'publisher_subjects',
        'cited_by_policies_count', 'scopus_subjects', 'cited_by_msm_count',
        'cited_by_fbwalls_count', 'abstract_source', 'cited_by_patents_count',
        'cited_by_wikipedia_count', 'downloads', 'cited_by_weibo_count',
        'cited_by_feeds_count', 'cited_by_peer_review_sites_count',
        'cited_by_rdts_count', 'cited_by_videos_count', 'cited_by_gplus_count',
        'cited_by_rh_count', 'handle', 'ordinal_number',
        'cited_by_linkedin_count', 'cited_by_pinners_count', 'arxiv_id',
        'cited_by_qna_count', 'attribution', 'editors'
    ])

    for pmid in pmids:

        try:
            response = a.pmid(pmid)
        except Exception as err:
            print("Failed altmetric query for " + str(pmid))
            response = None

        if response != None:
            df = pd.DataFrame.from_dict(response, orient='index').transpose()
        else:
            df = pd.DataFrame(columns=[
                'title', 'doi', 'pmid', 'pmc', 'ads_id', 'isbns',
                'altmetric_jid', 'issns', 'journal', 'cohorts', 'abstract',
                'context', 'authors', 'type', 'handles', 'altmetric_id',
                'schema', 'is_oa', 'cited_by_posts_count',
                'cited_by_tweeters_count', 'cited_by_accounts_count',
                'last_updated', 'score', 'history', 'url', 'added_on',
                'published_on', 'subjects', 'readers', 'readers_count',
                'images', 'details_url', 'uri', 'publisher_subjects',
                'cited_by_policies_count', 'scopus_subjects',
                'cited_by_msm_count', 'cited_by_fbwalls_count',
                'abstract_source', 'cited_by_patents_count',
                'cited_by_wikipedia_count', 'downloads',
                'cited_by_weibo_count', 'cited_by_feeds_count',
                'cited_by_peer_review_sites_count', 'cited_by_rdts_count',
                'cited_by_videos_count', 'cited_by_gplus_count',
                'cited_by_rh_count', 'handle', 'ordinal_number',
                'cited_by_linkedin_count', 'cited_by_pinners_count',
                'arxiv_id', 'cited_by_qna_count', 'attribution', 'editors'
            ])
            #df['pmid'] = str(pmid)
        altmet_df = altmet_df.append(df)
        #altmet_df = altmet_df.append(pd.DataFrame(response))
        altmet_df['pmid'] = altmet_df['pmid'].astype(str)
        altmet_df['last_import'] = [
            datetime.datetime.today().strftime("%Y-%m-%d")
        ] * len(altmet_df['pmid'])
        time.sleep(2)

    return altmet_df
예제 #9
0
파일: test6.py 프로젝트: etcluvic/sme.altm

if __name__ == '__main__':

    #https://github.com/wearp/pyaltmetric
    #https://api.altmetric.com/version/citations/timeframe
    #http://api.altmetric.com/docs/call_citations.html

    timeframe = '1d'
    resultsPerPage = 100
    resultsPage = 1
    doiPrefix = '10.7202'  #erudit's doi prefix
    pause = 1
    myTime = datetime.now().strftime('%Y-%m-%d_%H-%M-%S-%f')

    a = Altmetric(altmetricKey)

    query = a.citations(timeframe, doi_prefix=doiPrefix)
    totalResults = query['query']['total']
    print totalResults

    time.sleep(pause)

    for i, r in enumerate(range(1, totalResults, resultsPerPage), 1):
        print(i, r)

        query = a.citations(timeframe,
                            num_results=resultsPerPage,
                            page=i,
                            doi_prefix=doiPrefix)
        print(query)