Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,19 +16,21 @@ BSKY_PASSWORD = os.getenv("BSKY_PASSWORD", "Raira0626")
|
|
| 16 |
|
| 17 |
api = HfApi()
|
| 18 |
|
| 19 |
-
# --- カスタムCSS(
|
| 20 |
custom_css = """
|
| 21 |
-
/* 1列目(日付)と2列目(投稿者)
|
| 22 |
td:nth-child(1), th:nth-child(1),
|
| 23 |
td:nth-child(2), th:nth-child(2) {
|
| 24 |
-
width:
|
| 25 |
-
min-width:
|
| 26 |
-
max-width:
|
| 27 |
-
|
| 28 |
-
white-space: pre
|
| 29 |
-
font-size: 11px !important; /* 幅に合わせて少し小さく */
|
| 30 |
-
line-height: 1.2 !important;
|
| 31 |
overflow: hidden !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
/* 5列目(いいね数) */
|
|
@@ -38,9 +40,9 @@ td:nth-child(5), th:nth-child(5) {
|
|
| 38 |
text-align: center !important;
|
| 39 |
}
|
| 40 |
|
| 41 |
-
/* テーブル全体のフォントサイズ */
|
| 42 |
table {
|
| 43 |
-
|
|
|
|
| 44 |
}
|
| 45 |
"""
|
| 46 |
|
|
@@ -60,7 +62,7 @@ def get_filter_options():
|
|
| 60 |
return ["すべて"], ["すべて"]
|
| 61 |
|
| 62 |
def make_clickable(url):
|
| 63 |
-
return f'<a href="{url}" target="_blank" style="color: #008DFF; text-decoration: underline;">
|
| 64 |
|
| 65 |
def fetch_and_save(target_hashtag="#青空怪文庫", max_total=300):
|
| 66 |
try:
|
|
@@ -85,8 +87,8 @@ def fetch_and_save(target_hashtag="#青空怪文庫", max_total=300):
|
|
| 85 |
display_text = getattr(post.record, 'text', "")
|
| 86 |
display_url = f"https://bsky.app/profile/{post.author.did}/post/{post.uri.split('/')[-1]}"
|
| 87 |
|
| 88 |
-
# 日付を YYYY-\nMM-DD に
|
| 89 |
-
raw_date = post.record.created_at[:10]
|
| 90 |
formatted_date = f"{raw_date[:5]}\n{raw_date[5:]}"
|
| 91 |
|
| 92 |
if hasattr(post, 'embed') and post.embed is not None:
|
|
@@ -106,7 +108,7 @@ def fetch_and_save(target_hashtag="#青空怪文庫", max_total=300):
|
|
| 106 |
|
| 107 |
original_url = f"https://bsky.app/profile/{quoted_record.author.did}/post/{quoted_record.uri.split('/')[-1]}"
|
| 108 |
display_author = original_author
|
| 109 |
-
display_text = f"{original_text}\n\n({tagger_name}
|
| 110 |
display_url = original_url
|
| 111 |
|
| 112 |
new_data.append({
|
|
@@ -148,16 +150,15 @@ def search_data(author_val, tag_val, keyword_val):
|
|
| 148 |
df['URL'] = df['URL'].apply(make_clickable)
|
| 149 |
return df
|
| 150 |
|
| 151 |
-
# UI 構築
|
| 152 |
with gr.Blocks(css=custom_css) as demo:
|
| 153 |
-
gr.Markdown("# 👻 青空怪文庫
|
| 154 |
|
| 155 |
with gr.Tabs():
|
| 156 |
-
with gr.TabItem("🔍
|
| 157 |
with gr.Row():
|
| 158 |
author_dropdown = gr.Dropdown(label="投稿者", choices=["すべて"], value="すべて")
|
| 159 |
-
tag_dropdown = gr.Dropdown(label="
|
| 160 |
-
|
| 161 |
with gr.Row():
|
| 162 |
search_btn = gr.Button("検索実行", variant="primary")
|
| 163 |
clear_btn = gr.Button("リセット")
|
|
@@ -169,7 +170,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 169 |
type="pandas"
|
| 170 |
)
|
| 171 |
|
| 172 |
-
with gr.TabItem("🔄
|
| 173 |
with gr.Row():
|
| 174 |
tag_input = gr.Textbox(label="タグ", value="青空怪文庫")
|
| 175 |
count_input = gr.Slider(minimum=50, maximum=500, step=50, label="件数", value=300)
|
|
|
|
| 16 |
|
| 17 |
api = HfApi()
|
| 18 |
|
| 19 |
+
# --- カスタムCSS(2行固定と幅の厳格な管理) ---
|
| 20 |
custom_css = """
|
| 21 |
+
/* 1列目(日付)と2列目(投稿者) */
|
| 22 |
td:nth-child(1), th:nth-child(1),
|
| 23 |
td:nth-child(2), th:nth-child(2) {
|
| 24 |
+
width: 60px !important;
|
| 25 |
+
min-width: 60px !important;
|
| 26 |
+
max-width: 60px !important;
|
| 27 |
+
/* 指定した改行以外は無視し、はみ出しは隠す */
|
| 28 |
+
white-space: pre !important;
|
|
|
|
|
|
|
| 29 |
overflow: hidden !important;
|
| 30 |
+
text-overflow: ellipsis !important;
|
| 31 |
+
font-size: 12px !important;
|
| 32 |
+
line-height: 1.2 !important;
|
| 33 |
+
padding: 4px 2px !important;
|
| 34 |
}
|
| 35 |
|
| 36 |
/* 5列目(いいね数) */
|
|
|
|
| 40 |
text-align: center !important;
|
| 41 |
}
|
| 42 |
|
|
|
|
| 43 |
table {
|
| 44 |
+
table-layout: fixed !important;
|
| 45 |
+
width: 100% !important;
|
| 46 |
}
|
| 47 |
"""
|
| 48 |
|
|
|
|
| 62 |
return ["すべて"], ["すべて"]
|
| 63 |
|
| 64 |
def make_clickable(url):
|
| 65 |
+
return f'<a href="{url}" target="_blank" style="color: #008DFF; text-decoration: underline;">URL</a>'
|
| 66 |
|
| 67 |
def fetch_and_save(target_hashtag="#青空怪文庫", max_total=300):
|
| 68 |
try:
|
|
|
|
| 87 |
display_text = getattr(post.record, 'text', "")
|
| 88 |
display_url = f"https://bsky.app/profile/{post.author.did}/post/{post.uri.split('/')[-1]}"
|
| 89 |
|
| 90 |
+
# 日付を YYYY-\nMM-DD に整形 (ハイフンを含めて5文字+改行)
|
| 91 |
+
raw_date = post.record.created_at[:10] # YYYY-MM-DD
|
| 92 |
formatted_date = f"{raw_date[:5]}\n{raw_date[5:]}"
|
| 93 |
|
| 94 |
if hasattr(post, 'embed') and post.embed is not None:
|
|
|
|
| 108 |
|
| 109 |
original_url = f"https://bsky.app/profile/{quoted_record.author.did}/post/{quoted_record.uri.split('/')[-1]}"
|
| 110 |
display_author = original_author
|
| 111 |
+
display_text = f"{original_text}\n\n({tagger_name} 紹介)"
|
| 112 |
display_url = original_url
|
| 113 |
|
| 114 |
new_data.append({
|
|
|
|
| 150 |
df['URL'] = df['URL'].apply(make_clickable)
|
| 151 |
return df
|
| 152 |
|
|
|
|
| 153 |
with gr.Blocks(css=custom_css) as demo:
|
| 154 |
+
gr.Markdown("# 👻 青空怪文庫 DB")
|
| 155 |
|
| 156 |
with gr.Tabs():
|
| 157 |
+
with gr.TabItem("🔍 検索"):
|
| 158 |
with gr.Row():
|
| 159 |
author_dropdown = gr.Dropdown(label="投稿者", choices=["すべて"], value="すべて")
|
| 160 |
+
tag_dropdown = gr.Dropdown(label="タグ", choices=["すべて"], value="すべて")
|
| 161 |
+
keyword_search = gr.Textbox(label="キーワード", placeholder="キーワード...")
|
| 162 |
with gr.Row():
|
| 163 |
search_btn = gr.Button("検索実行", variant="primary")
|
| 164 |
clear_btn = gr.Button("リセット")
|
|
|
|
| 170 |
type="pandas"
|
| 171 |
)
|
| 172 |
|
| 173 |
+
with gr.TabItem("🔄 更新"):
|
| 174 |
with gr.Row():
|
| 175 |
tag_input = gr.Textbox(label="タグ", value="青空怪文庫")
|
| 176 |
count_input = gr.Slider(minimum=50, maximum=500, step=50, label="件数", value=300)
|