python参考文献目录_[zotero/python]库中参考文献条目删除后,清除残留PDF的脚本
# -*- coding: utf-8 -*-
"""Spyder Editor"""
from __future__ import print_function
from os import walk, remove
import os
import re
import tkinter as tk
from tkinter import filedialog
import shutil #移动或复制文件
import sqlite3
import pandas as pd
import configparser
import shutil
import sys
root = tk.Tk()
root.withdraw()
#选择PDF备份的目录
back_dir = filedialog.askdirectory(title = '请选择PDF备份的目录:')
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
if sys.version_info.major == 2:
reload(sys)
sys.setdefaultencoding('UTF8')
def get_zotfile_dest_and_zotero_data_dirs():
'''Get the Zotero data dir and the Zotfile destination dir in PosixPath type'''
profile_dirs = {
'darwin': Path.home() / 'Library/Application Support/Zotero',
'linux': Path.home() / '.zotero/zotero',
'linux2': Path.home() / '.zotero/zotero',
'win32': Path.home() / 'AppData/Roaming/Zotero/Zotero'
}
profile_dir = profile_dirs[sys.platform]
config = configparser.ConfigParser()
config.read('{}'.format(profile_dir / 'profiles.ini'))
configs_loc = profile_dir / config['Profile0']['Path'] / 'prefs.js'
configs = configs_loc.read_text()
zotero_data_pat = re.compile(
r'user_pref\("extensions.zotero.dataDir",\ "(?P.+)"\);')
zotero_data_dir = Path(zotero_data_pat.search(
configs).group('zotero_data'))
zotfile_dest_pat = re.compile(
r'user_pref\("extensions.zotfile.dest_dir",\ "(?P.+)"\);')
zotfile_dest_dir = Path(
zotfile_dest_pat.search(configs).group('zotfile_dest'))
return zotero_data_dir, zotfile_dest_dir
if __name__ == '__main__':
#得到zotero数据目录和文件目录
zotero_data_dir, zotfile_dest_dir = get_zotfile_dest_and_zotero_data_dirs()
list_of_files = [] #文件包含目录
files = [] #仅文件名
for (dirpath, dirnames, filenames) in walk(zotfile_dest_dir):
for file in filenames:
if file.endswith('.pdf') == True:
list_of_files.append(os.path.join(dirpath, file))
files.append(file)
#连接数据库
zot_sqlite = os.path.join(zotero_data_dir, 'zotero.sqlite')
with sqlite3.connect(zot_sqlite) as con:
item_att=pd.read_sql_query("SELECT * FROM itemAttachments", con=con)
item_path = item_att['path']
#生成备份文件目录
#当文件不存在时,才创建该文件夹。
if not os.path.exists(back_dir):
os.mkdir(back_dir)
for i in range(len(files)):
#如zotero.sqlite的path中不包括文件
if not (item_path.str.contains(re.escape(files[i])).any()):
#os.remove(list_of_files[i]) #也可以删除文件
shutil.move(list_of_files[i], os.path.join(back_dir, files[i]))#移动文件到备份目录
print('已备份',files[i],'到',back_dir)
python参考文献目录_[zotero/python]库中参考文献条目删除后,清除残留PDF的脚本相关推荐
- python参考文献_[zotero/python]库中参考文献条目删除后,清除残留PDF的脚本
更新:使用 @滏阳河边捉蚯蚓 https://zhuanlan.zhihu.com/p/41297136上获取系统PDF文件和zotero.sqlite文件的代码,在此感谢! 在zotero的libr ...
- python pptx教学_基于python-pptx库中文文档及使用详解
个人使用样例及部分翻译自官方文档,并详细介绍chart的使用 一:基础应用 1.创建pptx文档类并插入一页幻灯片 from pptx import Presentation prs = Presen ...
- python svr回归_使用sklearn库中的SVR做回归分析
sklearn中的回归有多种方法,广义线性回归集中在linear_model库下,例如普通线性回归.Lasso.岭回归等:另外还有其他非线性回归方法,例如核svm.集成方法.贝叶斯回归.K近邻回归.决 ...
- python缓存技术_高级Python技术:如何在Python应用程序中实现缓存
缓存的重要性 缓存对于每个Python程序员来说都是一个需要理解的重要概念. 简而言之,缓存的概念主要是利用编程技术将数据存储在临时位置,而不是每次都从源检索数据. 随后,缓存可以提高应用程序的性能, ...
- python 时间序列预测_使用Python进行动手时间序列预测
python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...
- python 概率分布模型_使用python的概率模型进行公司估值
python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...
- python fetchall方法_索引Python fetchall()
我正在尝试如何在MySQL中使用Python.我在处理查询结果中的条目时遇到问题.在 所以如果我这样做:import MySQLdb db = MySQLdb.connect(host="1 ...
- 注册表中exe被删除后恢复
恢复注册表 如果我们不小心将注册表中的exe删除后,这个时候不管打开什么软件都需我们自己进行指定才能打开使用,这样是及其麻烦的,而且在删除掉.exe之后,原来能在"运行"中搜索 ...
- python pptx库中文文档_基于python-pptx库中文文档及使用详解
个人使用样例及部分翻译自官方文档,并详细介绍chart的使用 一:基础应用 1.创建pptx文档类并插入一页幻灯片 from pptx import Presentation prs = Presen ...
最新文章
- android绘制环形进度_android 圆环进度view
- FTP服务器的防火墙通用设置规则
- 如何判断设备是上电复位还是软复位(主动调用复位接口或者看门狗复位,W600)
- LATEX论文排版学习资源汇总
- python opencv resize函数_Python OpenCV中的resize()函数的使用
- 《剑指offer》把二叉树打印成多行
- leetcode133. 克隆图(bfs)
- 搜索引擎的十大秘密(收藏)
- 海龟交易法则14_掌控心魔
- 拓端tecdat|R语言生态学建模:增强回归树(BRT)预测短鳍鳗生存分布和影响因素
- 关于FND_PROFILE与FND_GLOBLE[Z]
- Python代码混淆工具,Python源代码保密、加密、混淆
- STM32借助Mbed OS多线程调节电脑音量
- 单片机蓝桥杯之LED点亮(国信CT107D开发板)
- mpu和嵌入式linux区别,嵌入式MCU与MPU的区分和MCU开发中的三个误区
- 物理思维在计算机中的应用,思维导图学物理 学会用大脑的语言进行思考
- CAP 定理、 BASE 理论
- 听书笔记:《勇敢去敲老板的门》
- 指挥调度中心如何选择调度台?
- 利用浏览器的 window.print();打印分层表格【强制换页的关键】