Skip to content

Instantly share code, notes, and snippets.

@AdoHaha
Created April 25, 2023 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdoHaha/a2fe95bb26866070bd0f8a1c5610869e to your computer and use it in GitHub Desktop.
Save AdoHaha/a2fe95bb26866070bd0f8a1c5610869e to your computer and use it in GitHub Desktop.
'''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