惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
I
InfoQ
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园_首页
罗磊的独立博客
V
V2EX
李成银的技术随笔
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
True Tiger Recordings
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
F
Fox-IT International blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
M
Microsoft Research Blog - Microsoft Research
Know Your Adversary
Know Your Adversary
爱范儿
爱范儿
The Register - Security
The Register - Security
G
Google Developers Blog
The Hacker News
The Hacker News
Malwarebytes
Malwarebytes
S
Securelist
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
博客园 - 叶小钗
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
博客园 - 聂微东
T
Threatpost
博客园 - 【当耐特】
D
Docker
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
V
Visual Studio Blog
C
Cisco Blogs
IT之家
IT之家
S
Security Archives - TechRepublic
Latest news
Latest news
阮一峰的网络日志
阮一峰的网络日志

智朋的个人博客

使用 PyQt 制作简易软件简明笔记 制作 Anki 插件简明笔记 LaTeX 图片背景 eso-pic 宏包 残余应力 文件树目录 Excel 操作指南 Word 操作指南 Mermaid 甘特图 QHUMaster 使用指南 QHUMaster 使用指南
Anki 笔记读取器
2024-10-05 · via 智朋的个人博客
1
2
3
4
5
6
7
8
9
10
11
(0, 'id', 'INTEGER', 0, None, 1)  
(1, 'guid', 'TEXT', 1, None, 0)
(2, 'mid', 'INTEGER', 1, None, 0)
(3, 'mod', 'INTEGER', 1, None, 0)
(4, 'usn', 'INTEGER', 1, None, 0)
(5, 'tags', 'TEXT', 1, None, 0)
(6, 'flds', 'TEXT', 1, None, 0)
(7, 'sfld', 'INTEGER', 1, None, 0)
(8, 'csum', 'INTEGER', 1, None, 0)
(9, 'flags', 'INTEGER', 1, None, 0)
(10, 'data', 'TEXT', 1, None, 0)
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from flask import Flask, request, send_from_directory, render_template, send_file
import sqlite3
import pandas as pd
import os
import re
import csv

app = Flask(__name__)


DATABASE_PATH = r'C:\Users\Administrator\Desktop\collection.anki2'
MEDIA_PATH = r'C:\Users\Administrator\AppData\Roaming\Anki2\账户1\collection.media'


@app.route('/media/<path:filename>')
def media(filename):
full_path = os.path.join(MEDIA_PATH, filename)
print(f"Attempting to access: {full_path}")
return send_from_directory(MEDIA_PATH, filename)

def query_database(query, params):
"""执行 SQL 查询并返回结果为 DataFrame"""
conn = sqlite3.connect(DATABASE_PATH)
df = pd.read_sql_query(query, conn, params=params)
conn.close()
return df

@app.route('/', methods=['GET', 'POST'])
def index():
results = []
message = ""
if request.method == 'POST':
search_term = request.form.get('term', '')
print(f"Searching for: {search_term}")









query = """
SELECT id, flds
FROM notes
WHERE flds LIKE ?
"""

try:
results_df = query_database(query, (f'%{search_term}%',))
print(f"Query results: {results_df}")
if results_df.empty:
message = "未找到相关结果。"
else:
for _, row in results_df.iterrows():
fields = row['flds'].split('\x1f')
print(f"Fields content: {fields}")

for i, field in enumerate(fields):
matches = re.findall(r'src="([^"]+\.(?:jpg|png|gif))"', field)
for match in matches:
img_tag = f' class="image" src="/media/{match}" alt="Image" '
field = re.sub(r'src="[^"]*"', img_tag, field, count=1)
fields[i] = field.strip()





results.append({'id': row['id'], 'flds': fields})

except Exception as e:
message = f"查询错误: {str(e)}"
print(message)


return render_template('index.html', results=results, message=message)


@app.route('/export', methods=['GET'])
def export_notes():
search_term = request.args.get('term', '')
print(f"导出请求,搜索词: {search_term}")







query = """
SELECT id, flds
FROM notes
WHERE flds LIKE ?
"""

try:
results_df = query_database(query, (f'%{search_term}%',))
temp_file = 'exported_notes.csv'


results_df.to_csv(temp_file, index=False, encoding='utf-8-sig')

return send_file(temp_file, as_attachment=True)

except Exception as e:
print(f"导出错误: {str(e)}")
return "导出失败", 500

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)