def update_articles():
    print 'Updating articles'
    all_arts = m.Article.objects.all()
    pmid_list = [a.pmid for a in all_arts]
    pmid_list_len = len(pmid_list)
    for i,pmid in enumerate(pmid_list):
        prog(i, pmid_list_len)
        a = m.Article.objects.filter(pmid=pmid)[0]
        if a.author_list_str is None:
            add_single_article_full(pmid)
def add_ephys_nedm(ephys_name, ephys_value, pmid, neuron_type, user, overwrite=True):
    if ephys_value is '':
        return
    
    ephys_value_list = resolve.resolve_data_float(ephys_value)
    
    if not 'error' in ephys_value_list:
        ephys_value_list['error'] = None
        
    if not 'numCells' in ephys_value_list:
        ephys_value_list['numCells'] = None
    
    a = pubmed_functions.add_single_article_full(pmid)

    n = m.Neuron.objects.filter(name = neuron_type)[0]
    us_ob = m.UserSubmission.objects.get_or_create(user = user, article = a)[0]
    ds_ob = m.DataSource.objects.get_or_create(user_submission = us_ob)[0]
    ncm_ob = m.NeuronConceptMap.objects.get_or_create(source = ds_ob, added_by = user, neuron = n, 
                                                        times_validated = 1)[0]
    
    ephys_prop_ob = m.EphysProp.objects.get(name = ephys_name)
    ecm_ob = m.EphysConceptMap.objects.get_or_create(ephys_prop = ephys_prop_ob, source = ds_ob, added_by = user,
                                                        times_validated = 1)[0]
    ds_ob.save()

    try:
        nedm = m.NeuronEphysDataMap.objects.get(source = ds_ob,
                                         added_by = user,
                                         neuron_concept_map = ncm_ob,
                                         ephys_concept_map = ecm_ob)
        if overwrite is True:
            nedm.delete()
    except ObjectDoesNotExist:
        pass
    # if overwrite is false, just make a new nedm, otherwise find the old nedm (if it exists) and then overwrite it

    m.NeuronEphysDataMap.objects.get_or_create(source = ds_ob,
                                               added_by = user,
                                               neuron_concept_map = ncm_ob,
                                               ephys_concept_map = ecm_ob,
                                               val = ephys_value_list['value'],
                                               val_norm = ephys_value_list['value'],
                                               err = ephys_value_list['error'],
                                               times_validated = 1,
                                               n = ephys_value_list['numCells'],
                                             )[0]
        return None
    journal_name = get_journal(pmid_str)
    # is journal one among list of full text journals?
    if not isFullTextJournal(journal_name):
        #       with open("analyzed_files.txt", "a") as af:
        #           write_str = '%s\n' % file_name
        #           af.write(write_str)
        print "Journal %s is not a full text journal, skipping..." % journal_name
        return None
    # does journal already have full text assoc with it?
    if m.ArticleFullText.objects.filter(article__pmid=pmid_str).count() > 0:
        print "Article %s already in db, skipping..." % pmid_str
        return None

    print "adding article with pmid: %s" % pmid_str
    a = add_single_article_full(int(pmid_str))
    if a is None:
        #         f.close()
        return None

    try:
        print "adding %s as %s" % (file_name, a.pmid)
        f = open(unicode(file_name), "r")
        file_ob = File(f)
        os.chdir(settings.PROJECT_BASE_DIRECTORY)
        aft = m.ArticleFullText.objects.get_or_create(article=a)[0]
        aft.full_text_file.save(file_name, file_ob)
        file_ob.close()

        file_ext = os.path.splitext(file_name)
        # first check if any tables