Update search.py

Added filters to prevent the same message id from appearing twice in searchcord if it gets scraped more than once for some reason, added more info (time sent, message id ect)
This commit is contained in:
koshiro 2025-09-20 03:09:16 -05:00 committed by GitHub
parent d2024ad45d
commit 2e34e9128a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,22 +7,27 @@ app = Flask(__name__)
# Load all JSON files from current directory # Load all JSON files from current directory
DATA = [] DATA = []
FILES = [f for f in os.listdir('.') if f.endswith('.json')] FILES = [f for f in os.listdir('.') if f.endswith('.json')]
seen_ids = set()
for f in FILES: for f in FILES:
with open(f, 'r', encoding='utf-8') as file: with open(f, 'r', encoding='utf-8') as file:
try: try:
messages = json.load(file) messages = json.load(file)
for msg in messages: for msg in messages:
msg['source'] = f.replace('.json', '') msg_id = msg.get('id')
DATA.extend(messages) if msg_id and msg_id not in seen_ids:
seen_ids.add(msg_id)
msg['source'] = f.replace('.json', '')
DATA.append(msg)
except Exception: except Exception:
pass pass
# HTML Template with modern UI # HTML Template with animations
HTML = """ HTML = """
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Discord Scraper Viewer</title> <title>Searchcord Viewer</title>
<style> <style>
body { body {
font-family: 'Segoe UI', Tahoma, sans-serif; font-family: 'Segoe UI', Tahoma, sans-serif;
@ -41,7 +46,7 @@ HTML = """
letter-spacing: 1px; letter-spacing: 1px;
} }
main { main {
max-width: 900px; max-width: 950px;
margin: 20px auto; margin: 20px auto;
padding: 15px; padding: 15px;
} }
@ -74,9 +79,12 @@ HTML = """
.message { .message {
background: #2d2d44; background: #2d2d44;
padding: 15px; padding: 15px;
margin: 12px 0; margin: 15px 0;
border-radius: 12px; border-radius: 12px;
box-shadow: 0px 2px 6px rgba(0,0,0,0.4); box-shadow: 0px 2px 6px rgba(0,0,0,0.4);
opacity: 0;
transform: translateY(20px);
animation: fadeInUp 0.5s forwards;
} }
.username { .username {
font-weight: bold; font-weight: bold;
@ -95,7 +103,7 @@ HTML = """
border-radius: 10px; border-radius: 10px;
border: 2px solid #0077ff; border: 2px solid #0077ff;
} }
.source { .meta {
font-size: 0.8em; font-size: 0.8em;
margin-top: 8px; margin-top: 8px;
color: #9d9d9d; color: #9d9d9d;
@ -115,10 +123,14 @@ HTML = """
#loadMore:hover { #loadMore:hover {
background: #d20072; background: #d20072;
} }
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
</style> </style>
</head> </head>
<body> <body>
<header>📂 Discord Scraper Viewer</header> <header>🔍 Searchcord Viewer</header>
<main> <main>
<div class="search-bar"> <div class="search-bar">
<input type="text" id="search" placeholder="Search username or message..."> <input type="text" id="search" placeholder="Search username or message...">
@ -154,7 +166,9 @@ HTML = """
html += '<div class="username">' + msg.username + '</div>'; html += '<div class="username">' + msg.username + '</div>';
html += '<div class="text">' + msg.message + '</div>'; html += '<div class="text">' + msg.message + '</div>';
if (msg.img) html += '<img class="img" src="' + msg.img + '">'; if (msg.img) html += '<img class="img" src="' + msg.img + '">';
html += '<div class="source">From: ' + msg.source + '</div>'; html += '<div class="meta">From: ' + msg.source + '</div>';
html += '<div class="meta">Sent: ' + msg.time_sent + '</div>';
html += '<div class="meta">Message ID: ' + msg.id + '</div>';
html += '</div>'; html += '</div>';
container.innerHTML += html; container.innerHTML += html;
} }
@ -175,7 +189,10 @@ def search():
query = request.args.get('query', '').lower() query = request.args.get('query', '').lower()
if not query: if not query:
return jsonify(DATA[:200]) # default show some data return jsonify(DATA[:200]) # default show some data
results = [msg for msg in DATA if query in msg.get('username','').lower() or query in msg.get('message','').lower()] results = [
msg for msg in DATA
if query in msg.get('username', '').lower() or query in msg.get('message', '').lower()
]
return jsonify(results) return jsonify(results)
if __name__ == "__main__": if __name__ == "__main__":