Esempio n. 1
0
def pmc_url(value):
    '''Template tag filter go generate a direct link to this PubMed
    Central article, based on a numeric PubMed Central ID.'''
    try:
        value = int(value)
    except ValueError:
        return u''
    return pmc_access_url(value)
Esempio n. 2
0
def pmc_url(value):
    '''Template tag filter go generate a direct link to this PubMed
    Central article, based on a numeric PubMed Central ID.'''
    try:
        value = int(value)
    except ValueError:
        return u''
    return pmc_access_url(value)
Esempio n. 3
0
 def access_url(self):
     'Direct link to this PubMed Central article, based on PubMed Central ID.'
     return pmc_access_url(self.pmcid)
Esempio n. 4
0
    def handle(self, *args, **options):
        self.verbosity = int(options['verbosity'])    # 1 = normal, 0 = minimal, 2 = all
        self.v_normal = 1

        #counters
        counts = defaultdict(int)

        # check required options
        if not options['username']:
            raise CommandError('Username is required')
        else:
            if not options['password'] or options['password'] == '':
                options['password'] = getpass()

        #connection to repository
        repo = Repository(username=options['username'], password=options['password'])



        try:
            #if pids specified, use that list
            if len(args) != 0:
                pids = list(args)
                pid_set = [repo.get_object(pid=p, type=Publication) for p in pids]

            else:
                #search for Articles
                pid_set = repo.get_objects_with_cmodel(Publication.ARTICLE_CONTENT_MODEL, Article)

        except Exception as e:
            raise CommandError('Error gettings pids (%s)' % e.message)

        try:
            articles = Paginator(pid_set, 20)
            counts['total'] = articles.count
        except Exception as e:
            self.output(0, "Error paginating items: : %s " % (e.message))

        #process all Articles
        for p in articles.page_range:
            try:
                objs = articles.page(p).object_list
            except Exception as e:
                #print error and go to next iteration of loop
                self.output(0,"Error getting page: %s : %s " % (p, e.message))
                counts['errors'] +=1
                continue
            for article in objs:
                try:
                    if not article.exists:
                        self.output(1, "Skipping %s because pid does not exist" % article.pid)
                        counts['skipped'] +=1
                        continue
                    else:
                        self.output(0,"Processing %s" % article.pid)

                        mods = article.descMetadata.content
                        nlm = article.contentMetadata.content if article.contentMetadata.exists else None
                        identifiers = []

                        #PMC info
                        if nlm:
                            pmc = nlm.docid
                            pmc_id = 'PMC%s' % pmc
                            access_url = pmc_access_url(pmc)
                            identifiers.extend([pmc_id, access_url])

                        if mods.ark_uri:
                            identifiers.append(mods.ark_uri)

                        identifiers.append(article.pid)

                        article.dc.content.identifier_list = identifiers

                        ##########REMOVE dc.relation###########
                        #                                     #
                        article.dc.content.relation_list = [] #
                        #                                     #
                        #######################################

                        # save article
                        if not options['noact']:
                            article.save()
                            self.output(1, "SAVED")
                except Exception as e:
                    self.output(0, "Error processing pid: %s : %s " % (article.pid, e.message))
                    counts['errors'] +=1

        # summarize what was done
        self.stdout.write("\n\n")
        self.stdout.write("Total number selected: %s\n" % counts['total'])
        self.stdout.write("Skipped: %s\n" % counts['skipped'])
        self.stdout.write("Errors: %s\n" % counts['errors'])
Esempio n. 5
0
 def access_url(self):
     'Direct link to this PubMed Central article, based on PubMed Central ID.'
     return pmc_access_url(self.pmcid)
Esempio n. 6
0
    def handle(self, *args, **options):
        self.verbosity = int(
            options['verbosity'])  # 1 = normal, 0 = minimal, 2 = all
        self.v_normal = 1

        #counters
        counts = defaultdict(int)

        # check required options
        if not options['username']:
            raise CommandError('Username is required')
        else:
            if not options['password'] or options['password'] == '':
                options['password'] = getpass()

        #connection to repository
        repo = Repository(username=options['username'],
                          password=options['password'])

        try:
            #if pids specified, use that list
            if len(args) != 0:
                pids = list(args)
                pid_set = [repo.get_object(pid=p, type=Article) for p in pids]

            else:
                #search for Articles
                pid_set = repo.get_objects_with_cmodel(
                    Article.ARTICLE_CONTENT_MODEL, Article)

        except Exception as e:
            raise CommandError('Error gettings pids (%s)' % e.message)

        try:
            articles = Paginator(pid_set, 20)
            counts['total'] = articles.count
        except Exception as e:
            self.output(0, "Error paginating items: : %s " % (e.message))

        #process all Articles
        for p in articles.page_range:
            try:
                objs = articles.page(p).object_list
            except Exception as e:
                #print error and go to next iteration of loop
                self.output(0, "Error getting page: %s : %s " % (p, e.message))
                counts['errors'] += 1
                continue
            for article in objs:
                try:
                    if not article.exists:
                        self.output(
                            1, "Skipping %s because pid does not exist" %
                            article.pid)
                        counts['skipped'] += 1
                        continue
                    else:
                        self.output(0, "Processing %s" % article.pid)

                        mods = article.descMetadata.content
                        nlm = article.contentMetadata.content if article.contentMetadata.exists else None
                        identifiers = []

                        #PMC info
                        if nlm:
                            pmc = nlm.docid
                            pmc_id = 'PMC%s' % pmc
                            access_url = pmc_access_url(pmc)
                            identifiers.extend([pmc_id, access_url])

                        if mods.ark_uri:
                            identifiers.append(mods.ark_uri)

                        identifiers.append(article.pid)

                        article.dc.content.identifier_list = identifiers

                        ##########REMOVE dc.relation###########
                        #                                     #
                        article.dc.content.relation_list = []  #
                        #                                     #
                        #######################################

                        # save article
                        if not options['noact']:
                            article.save()
                            self.output(1, "SAVED")
                except Exception as e:
                    self.output(
                        0, "Error processing pid: %s : %s " %
                        (article.pid, e.message))
                    counts['errors'] += 1

        # summarize what was done
        self.stdout.write("\n\n")
        self.stdout.write("Total number selected: %s\n" % counts['total'])
        self.stdout.write("Skipped: %s\n" % counts['skipped'])
        self.stdout.write("Errors: %s\n" % counts['errors'])