Skip to content

Instantly share code, notes, and snippets.



Last active Sep 29, 2017
What would you like to do?
Searches through all of your texts for one matching a string
__author__ = "Alex Beals"
import sqlite3, markovify, codecs, warnings, os
# Handle errors from running on Python 2.7 (emoji support)
print("Connecting to chat database...")
# Extract all of my texts from the 'db' file
conn = sqlite3.connect(os.path.expanduser("~/Library/Messages/chat.db"))
c = conn.cursor()
# String to search for
search_query = 'test'
c.execute('SELECT text FROM message WHERE text LIKE "%' + search_query + '%"')
texts = c.fetchall()
for text in texts:
print text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment