bibrename.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:bibmanagement 作者: AlexandreRio 项目源码 文件源码
def rename_file(entry, pdf, bib, dry_run):
    if entry['author']:
        authors = entry['author'].split(',')
        if len(authors) <= 3:
            author = ', '.join(authors[:-1])
        else:
            author = authors[0] + ' et al.'

    if author and 'year' in entry and 'title' in entry:
        newname = author + ' - ' + '{}'.format(entry['year']) + ' - ' + algo.tex_to_unicode(algo.title_case(entry['title'])).replace("/", " ") + '.pdf'

        if os.path.exists(pdf):
            shutil.copy2(pdf, os.path.expanduser("~") + papers_path +  newname)
            entry.set_tag('file', ':' + pdf + ':PDF' )

            if not dry_run:
                shutil.move(pdf, os.path.expanduser("~") + '/.local/share/Trash/files/')
                return True
    return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号