コード例 #1
0
 def test_zotero_suggest_short_title(self):
     """Test the ZoteroRecord suggest_short_title method."""
     path = join('tests', 'data', 'zotero_sugg.csv')
     zc = ZoteroCollection()
     zc.load_csv(path)
     m = zc.match({'Title': 'Bill and Pete Go Down the Nile.'})
     assert_equal(len(m), 1)
     assert_equal(m[0].suggest_short_title(), 'DePaola 2009')
コード例 #2
0
def main(**kwargs):
    """
    main function
    """
    # logger = logging.getLogger(sys._getframe().f_code.co_name)
    path = abspath(realpath(kwargs['zotero_csv']))
    zc = ZoteroCollection()
    if kwargs['verbose']:
        print('Loading Zotero CSV file at {} ...'.format(path))
    zc.load_csv(path)
    if kwargs['verbose']:
        print('   Loaded {} records.'.format(len(zc)))
    criteria = {'required': ['Title', 'Short Title', 'Date']}
    if kwargs['verbose']:
        print('Validating ...')
    invalid_records = zc.validate(criteria)
    if kwargs['verbose']:
        print('   Validation complete.')
    print('There are {} invalid records.'.format(len(invalid_records)))
    outpath = None
    if kwargs['output'] != 'NOTSET':
        outpath = abspath(realpath(kwargs['output']))
        if not isdir(outpath):
            raise IOError('{} is not a directory'.format(path))
        outf = open(join(outpath, 'zotero_errors.csv'), 'w')
        fieldnames = ['key', 'title', 'criterion', 'fields', 'suggestion']
        writer = csv.DictWriter(outf,
                                fieldnames=fieldnames,
                                quoting=csv.QUOTE_NONNUMERIC)
        writer.writeheader()
    if kwargs['verbose'] or outpath is not None:
        for k, v in invalid_records.items():
            if kwargs['verbose']:
                print('INVALID Zotero Record {}:'.format(k))
                print('        {}'.format(zc.get_record(k)['Title']))
            for criterion, fields in v.items():
                if kwargs['verbose']:
                    print('        👾  {}: "{}"'
                          ''.format(criterion.upper(), '", "'.join(fields)))
                if outpath is not None:
                    if criterion == 'required' and fields == ['Short Title']:
                        suggestion = zc.get_record(k).suggest_short_title()
                    else:
                        suggestion = ''
                    writer.writerow({
                        'key': k,
                        'title': zc.get_record(k)['Title'],
                        'criterion': criterion,
                        'fields': '|'.join(fields),
                        'suggestion': suggestion
                    })
コード例 #3
0
 def test_zotero_collection(self):
     """Test Zotero collection"""
     data = [{
         'Key': '6S3UA6RW',
         'Item Type': 'blogPost',
         'Publication Year': '2009',
         'Author': 'Dempsey, Lorcan',
         'Title': "Discoverability .. a report that's worth a look",
         'Publication Title': "Lorcan Dempsey's weblog",
         'Url': 'http://orweblog.oclc.org/archives/002012.html',
         'Date': '2009-10-07',
         'Date Added': '2009-10-14 13:33:17',
         'Date Modified': '2009-10-14 13:33:58',
         'Access Date': '2009-10-14 13:33:17'
     }, {
         'Author': 'Erzen, Afif',
         'Call Number': 'DS51.T2 E79 1943',
         'Date': '1943',
         'Date Added': '2014-02-05 17:43:29',
         'Date Modified': '2016-02-25 11:15:05',
         'Extra': 'OCLC: 827268834',
         'Item Type': 'book',
         'Key': 'CUZWAHIZ',
         'Language': 'Turkish',
         'Library Catalog': 'Open WorldCat',
         'Num Pages': '30',
         'Place': 'İstanbul',
         'Publication Year': '1943',
         'Publisher': 'Maarif Matbaası',
         'Series': 'Maarif Vekilliği, Antikiteler ve Müzeler '
         'Direktörlüğü, Anıtları Koruma Kurulu',
         'Series Number': 'sayı 7',
         'Title': 'Tarsus kılavuzu'
     }]
     zc = ZoteroCollection(data)
     assert_equal(len(zc), 2)
     del zc
     zc = ZoteroCollection()
     assert_equal(len(zc), 0)
     zc.records = data
     assert_equal(len(zc), 2)
コード例 #4
0
def main(**kwargs):
    """
    main function
    """

    csv_path = abspath(realpath(kwargs['zotero_csv']))
    zc = ZoteroCollection()
    zc.load_csv(csv_path)
    logger.info('Zotero CSV loaded {} records'.format(len(zc)))

    json_path = abspath(realpath(kwargs['places_json']))
    pc = PlaceCrawler(json_path, count=False)
    place_refs = pc.get_references()
    logger.info('PlaceCrawler found {} places with references'.format(
        len(place_refs)))

    pecs_places = []
    for pid, pdata in place_refs.items():
        for ref in pdata['references']:
            if (ref.shortTitle == 'PECS' or ref.shortTitle.startswith('PECS ')
                    or ref.citationDetail.startswith('PECS ')
                    or ref.fullCitation.startswith('PECS ')):
                print('PECS!')
コード例 #5
0
 def test_zotero_match_and(self):
     """Test Zotero collection matching using logical 'and' operator."""
     path = join('tests', 'data', 'zotero.csv')
     zc = ZoteroCollection()
     zc.load_csv(path)
     m = zc.match({'Key': 'CUZWAHIZ'})
     assert_equal(len(m), 1)
     assert_equal(m[0]['Title'], 'Tarsus kılavuzu')
     m = zc.match({'Item Type': 'blogPost', 'Date': '2009-10-07'})
     assert_equal(
         str(m[0]),
         'ZoteroRecord(6S3UA6RW): "Discoverability .. a report that\'s '
         'worth a look"')
コード例 #6
0
 def test_zotero_validation(self):
     """Test Zotero library validation."""
     path = join('tests', 'data', 'zotero.csv')
     zc = ZoteroCollection()
     zc.load_csv(path)
     criteria = {'required': ['Title', 'ISSN']}
     invalid_records = zc.validate(criteria)
     assert_equal(len(invalid_records), 2)
     for k, v in invalid_records.items():
         assert_equal(v['required'][0], 'ISSN')
     criteria = {'required': ['Title', 'Canary']}
     invalid_records = zc.validate(criteria)
     assert_equal(len(invalid_records), 2)
     for k, v in invalid_records.items():
         assert_equal(v['unexpected'][0], 'Canary')
コード例 #7
0
 def test_zotero_match_notimplemented(self):
     """Test Zotero collection matching using and unexpected operator."""
     path = join('tests', 'data', 'zotero.csv')
     zc = ZoteroCollection()
     zc.load_csv(path)
     zc.match({'Key': 'CUZWAHIZ'}, operator='foo')
コード例 #8
0
 def test_zotero_collection_load_csv(self):
     """Test collection CSV loading"""
     path = join('tests', 'data', 'zotero.csv')
     zc = ZoteroCollection()
     zc.load_csv(path)
     assert_equal(len(zc), 2)