Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,8 @@ def search_logs(file, search_word, year, month, day):
|
|
| 29 |
if not log_lines:
|
| 30 |
return "", "ログファイルを先に読み込んでください。", None
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
# 両方の検索条件が入力されている場合はエラーを返す
|
| 35 |
if search_word.strip() and (year != "----" and month != "----" and day != "----"):
|
|
@@ -49,11 +50,12 @@ def search_logs(file, search_word, year, month, day):
|
|
| 49 |
start_date = datetime.strptime(search_date, "%Y/%m/%d")
|
| 50 |
end_date = start_date + timedelta(days=1)
|
| 51 |
results = extract_date_range_logs(log_lines, start_date, end_date)
|
| 52 |
-
results = [f"- {line}" for line in results]
|
| 53 |
search_condition = f"日付検索: {year}/{month}/{day}"
|
| 54 |
except ValueError:
|
| 55 |
return "", "無効な日付形式です。", None
|
| 56 |
|
|
|
|
| 57 |
formatted_results = "\n".join(results) if results else "一致する結果が見つかりませんでした。"
|
| 58 |
|
| 59 |
return formatted_results, f"{len(results)} 件の結果が見つかりました。", results, search_condition
|
|
@@ -93,7 +95,7 @@ def export_results(results, search_condition):
|
|
| 93 |
f.write(f"検索条件: {search_condition}\n")
|
| 94 |
f.write(f"ヒット件数: {len(results)} 件\n")
|
| 95 |
f.write("-" * 40 + "\n") # 区切り線
|
| 96 |
-
f.write("\n".join(results) + "\n") # 箇条書き
|
| 97 |
|
| 98 |
return file_path, "TXTファイルのダウンロードが可能になりました。"
|
| 99 |
except Exception as e:
|
|
|
|
| 29 |
if not log_lines:
|
| 30 |
return "", "ログファイルを先に読み込んでください。", None
|
| 31 |
|
| 32 |
+
# 検索条件の初期化
|
| 33 |
+
search_condition = "検索なし"
|
| 34 |
|
| 35 |
# 両方の検索条件が入力されている場合はエラーを返す
|
| 36 |
if search_word.strip() and (year != "----" and month != "----" and day != "----"):
|
|
|
|
| 50 |
start_date = datetime.strptime(search_date, "%Y/%m/%d")
|
| 51 |
end_date = start_date + timedelta(days=1)
|
| 52 |
results = extract_date_range_logs(log_lines, start_date, end_date)
|
| 53 |
+
results = [f"- {line.strip()}" for line in results]
|
| 54 |
search_condition = f"日付検索: {year}/{month}/{day}"
|
| 55 |
except ValueError:
|
| 56 |
return "", "無効な日付形式です。", None
|
| 57 |
|
| 58 |
+
# 検索結果を1行ずつ表示
|
| 59 |
formatted_results = "\n".join(results) if results else "一致する結果が見つかりませんでした。"
|
| 60 |
|
| 61 |
return formatted_results, f"{len(results)} 件の結果が見つかりました。", results, search_condition
|
|
|
|
| 95 |
f.write(f"検索条件: {search_condition}\n")
|
| 96 |
f.write(f"ヒット件数: {len(results)} 件\n")
|
| 97 |
f.write("-" * 40 + "\n") # 区切り線
|
| 98 |
+
f.write("\n".join(results) + "\n") # 必ず1行ずつ箇条書き
|
| 99 |
|
| 100 |
return file_path, "TXTファイルのダウンロードが可能になりました。"
|
| 101 |
except Exception as e:
|