Created
April 25, 2023 09:01
-
-
Save AdoHaha/a2fe95bb26866070bd0f8a1c5610869e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''searching for keywords based on chat gpt json user archive''' | |
import json | |
# Load the json file | |
with open('conversations.json') as json_file: | |
whole_string = json_file.read() | |
chats = json.loads(whole_string) | |
# Define keywords for searching | |
keywords = ['ransac'] | |
# Search for the chat title based on keywords | |
found_title = None | |
possible_titles = [] | |
for chat in chats: | |
for message_key, message_data in chat["mapping"].items(): | |
try: | |
message_parts = message_data.get("message", {}).get("content", {}).get("parts", []) | |
if all(keyword.lower() in " ".join(message_parts).lower() for keyword in keywords): | |
found_title = chat["title"] | |
break | |
except AttributeError: | |
pass | |
if found_title: | |
possible_titles.append(found_title) | |
found_title = None | |
if len(possible_titles)>0: | |
print(f"Found chat titles: {possible_titles}") | |
else: | |
print("No chat title found with the specified keywords.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment