From 2e34e9128a5bb470af8da9dceb161c90007a451b Mon Sep 17 00:00:00 2001 From: koshiro <163620373+k0shir0@users.noreply.github.com> Date: Sat, 20 Sep 2025 03:09:16 -0500 Subject: [PATCH] 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) --- search.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/search.py b/search.py index 52e451c..87498a5 100644 --- a/search.py +++ b/search.py @@ -7,22 +7,27 @@ app = Flask(__name__) # Load all JSON files from current directory DATA = [] FILES = [f for f in os.listdir('.') if f.endswith('.json')] +seen_ids = set() + for f in FILES: with open(f, 'r', encoding='utf-8') as file: try: messages = json.load(file) for msg in messages: - msg['source'] = f.replace('.json', '') - DATA.extend(messages) + msg_id = msg.get('id') + 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: pass -# HTML Template with modern UI +# HTML Template with animations HTML = """ - Discord Scraper Viewer + Searchcord Viewer -
📂 Discord Scraper Viewer
+
🔍 Searchcord Viewer
'; container.innerHTML += html; } @@ -175,7 +189,10 @@ def search(): query = request.args.get('query', '').lower() if not query: 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) if __name__ == "__main__":