Spaces:
Running
Running
CKB
commited on
Commit
·
ba68698
1
Parent(s):
f814ebd
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
import sqlite3
|
3 |
|
|
|
4 |
def search_db(query):
|
5 |
-
# 连接SQLite数据库
|
6 |
conn = sqlite3.connect('rarbg_db.sqlite')
|
7 |
cursor = conn.cursor()
|
8 |
-
|
9 |
-
# 拆分查询以便在标题中使用多个关键字
|
10 |
include_keywords = []
|
11 |
exclude_keywords = []
|
12 |
for keyword in query.split():
|
@@ -15,12 +13,9 @@ def search_db(query):
|
|
15 |
else:
|
16 |
include_keywords.append(keyword)
|
17 |
|
18 |
-
# 构建查询字符串
|
19 |
query_string = "SELECT title, hash, size, dt as time FROM items WHERE "
|
20 |
query_string += " AND ".join([f"title LIKE ?" for _ in include_keywords])
|
21 |
query_string += "".join([f" AND title NOT LIKE ?" for _ in exclude_keywords])
|
22 |
-
|
23 |
-
# 将关键字添加为通配符参数
|
24 |
params = [f"%{keyword}%" for keyword in include_keywords + exclude_keywords]
|
25 |
cursor.execute(query_string, params)
|
26 |
|
@@ -29,46 +24,36 @@ def search_db(query):
|
|
29 |
|
30 |
return results
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
# 创建Streamlit app
|
35 |
st.title("RARBG Database Search")
|
36 |
-
|
|
|
|
|
37 |
|
38 |
-
if st.button("
|
39 |
results = search_db(search_query)
|
40 |
if results:
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
# 创建HTML表格
|
45 |
-
html_table = '<table><tr><th>No.</th><th>Title with Magnet Link</th><th>Size (GB)</th><th>Time</th></tr>'
|
46 |
all_links = []
|
47 |
|
48 |
for i, (title, hash_value, size, time) in enumerate(results, start=1):
|
49 |
magnet_link = f'magnet:?xt=urn:btih:{hash_value}'
|
50 |
all_links.append(magnet_link)
|
51 |
-
|
52 |
-
# 检查 size 是否为 None
|
53 |
if size is not None:
|
54 |
size_gb = size / (1024 ** 3)
|
55 |
size_gb_str = f"{size_gb:.2f} GB"
|
56 |
else:
|
57 |
size_gb_str = "Unknown"
|
58 |
|
59 |
-
html_table += f'<tr><td>{i}</td><td><a href="{magnet_link}" target="_blank">{title}</a></td><td>{size_gb_str}</td><td>{time}</td></tr>'
|
60 |
-
|
61 |
html_table += '</table>'
|
62 |
-
|
63 |
-
# 使用markdown来渲染HTML表格
|
64 |
st.markdown(html_table, unsafe_allow_html=True)
|
65 |
-
|
66 |
-
#
|
67 |
-
|
68 |
-
|
69 |
-
st.
|
70 |
-
|
|
|
71 |
else:
|
72 |
-
st.write("
|
73 |
-
|
74 |
-
|
|
|
1 |
import streamlit as st
|
2 |
import sqlite3
|
3 |
|
4 |
+
|
5 |
def search_db(query):
|
|
|
6 |
conn = sqlite3.connect('rarbg_db.sqlite')
|
7 |
cursor = conn.cursor()
|
|
|
|
|
8 |
include_keywords = []
|
9 |
exclude_keywords = []
|
10 |
for keyword in query.split():
|
|
|
13 |
else:
|
14 |
include_keywords.append(keyword)
|
15 |
|
|
|
16 |
query_string = "SELECT title, hash, size, dt as time FROM items WHERE "
|
17 |
query_string += " AND ".join([f"title LIKE ?" for _ in include_keywords])
|
18 |
query_string += "".join([f" AND title NOT LIKE ?" for _ in exclude_keywords])
|
|
|
|
|
19 |
params = [f"%{keyword}%" for keyword in include_keywords + exclude_keywords]
|
20 |
cursor.execute(query_string, params)
|
21 |
|
|
|
24 |
|
25 |
return results
|
26 |
|
|
|
|
|
|
|
27 |
st.title("RARBG Database Search")
|
28 |
+
st.markdown("> 警告!本站不提供任何包含反动、淫秽、色情、暴力、侮辱、诽谤等不良信息。当你浏览本网站时,请自觉遵守法律法规,对自己的行为承担全部责任。")
|
29 |
+
st.markdown('> 使用说明:请在文本框内输入关键词,并点击搜索按钮进行查询。若需输入多个关键词,可用空格进行分隔;若希望某个关键词不在搜索结果中出现,可在关键词前加上 "-" 符号。')
|
30 |
+
search_query = st.text_input("输入搜索的关键词:")
|
31 |
|
32 |
+
if st.button("搜索"):
|
33 |
results = search_db(search_query)
|
34 |
if results:
|
35 |
+
st.write("结果:")
|
36 |
+
html_table = '<table style="width:100%; table-layout: fixed;"><tr><th>No.</th><th>标题</th><th>文件大小(GB)</th><th>时间</th></tr>'
|
|
|
|
|
|
|
37 |
all_links = []
|
38 |
|
39 |
for i, (title, hash_value, size, time) in enumerate(results, start=1):
|
40 |
magnet_link = f'magnet:?xt=urn:btih:{hash_value}'
|
41 |
all_links.append(magnet_link)
|
|
|
|
|
42 |
if size is not None:
|
43 |
size_gb = size / (1024 ** 3)
|
44 |
size_gb_str = f"{size_gb:.2f} GB"
|
45 |
else:
|
46 |
size_gb_str = "Unknown"
|
47 |
|
48 |
+
html_table += f'<tr><td style="overflow-wrap: break-word;">{i}</td><td style="overflow-wrap: break-word;"><a href="{magnet_link}" target="_blank">{title}</a></td><td style="overflow-wrap: break-word;">{size_gb_str}</td><td style="overflow-wrap: break-word;">{time}</td></tr>'
|
|
|
49 |
html_table += '</table>'
|
|
|
|
|
50 |
st.markdown(html_table, unsafe_allow_html=True)
|
51 |
+
# links_str = "\n".join(all_links)
|
52 |
+
# copy_html = f'{links_str}'
|
53 |
+
st.markdown("")
|
54 |
+
st.markdown("Telegram: @s_h_a_o_n_v")
|
55 |
+
# st.button("显示全部内容")
|
56 |
+
# st.markdown(copy_html, unsafe_allow_html=True)
|
57 |
+
# st.code(copy_html, language="textile", line_numbers=False)
|
58 |
else:
|
59 |
+
st.write("没有找到任何记录。")
|
|
|
|