Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-1106· OpenAIHugging Face Arena Human Preference 55K

Help me write a Python script that will search my macOS Safari history for any visited…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-3.5-turbo-0613’s answer.
  1. User

    Help me write a Python script that will search my macOS Safari history for any visited page related to “Nintendo”.

  2. Assistant

    You can use Python to search your macOS Safari history by accessing the SQLite database file where Safari stores the history. Here's an example script to get you started:

    import sqlite3
    
    def search_safari_history(keyword):
        try:
            # Connect to the Safari history database
            conn = sqlite3.connect('~/Library/Safari/History.db')
            cursor = conn.cursor()
    
            # Execute the SQL query to search for the keyword in the history
            cursor.execute("SELECT title, url, visit_time FROM history_items WHERE title LIKE ? OR url LIKE ?", ('%{}%'.format(keyword), '%{}%'.format(keyword)))
            results = cursor.fetchall()
    
            # Print the search results
            if results:
                print("Search results for keyword '{}':".format(keyword))
                for result in results:
                    print("Title: {}".format(result[0]))
                    print("URL: {}".format(result[1]))
                    print("Visit time: {}".format(result[2]))
                    print("")
    
            else:
                print("No results found for keyword '{}' in Safari history.".format(keyword))
    
            conn.close()
    
        except sqlite3.Error as e:
            print("Error accessing the Safari history database:", e)
    
    # Call the function to search for "Nintendo" in the Safari history
    search_safari_history("Nintendo")
    

    Before running the script, make sure to install the SQLite3 package by running pip install pysqlite3. Also, note that the path to the Safari history database may vary based on the macOS version, so you might need to adjust the path in the script.

    This script will connect to the Safari history database, execute a query to search for the keyword (in this case, "Nintendo"), and then print out the search results.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.