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

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
Microsoft Azure Blog
Microsoft Azure Blog
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cyberwarzone
Cyberwarzone
Recorded Future
Recorded Future
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threat Research - Cisco Blogs
Know Your Adversary
Know Your Adversary
Recent Announcements
Recent Announcements
L
LINUX DO - 热门话题
D
DataBreaches.Net
K
Kaspersky official blog
T
Threatpost
F
Full Disclosure
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
S
Securelist
I
Intezer
有赞技术团队
有赞技术团队
罗磊的独立博客
爱范儿
爱范儿
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LangChain Blog
美团技术团队
G
Google Developers Blog
T
Tor Project blog
Project Zero
Project Zero
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
W
WeLiveSecurity
Engineering at Meta
Engineering at Meta
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog

智朋的个人博客

使用 PyQt 制作简易软件简明笔记 制作 Anki 插件简明笔记 LaTeX 图片背景 eso-pic 宏包 残余应力 文件树目录 Excel 操作指南 Word 操作指南 Mermaid 甘特图 QHUMaster 使用指南 QHUMaster 使用指南
Anki 笔记读取器
coffeelize · 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)