Skip to content

Instantly share code, notes, and snippets.

@dado3212
Last active September 29, 2017 06:54
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 dado3212/27e4fdc1054eac8a4182b2810cd79ba8 to your computer and use it in GitHub Desktop.
Save dado3212/27e4fdc1054eac8a4182b2810cd79ba8 to your computer and use it in GitHub Desktop.
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)
warnings.simplefilter("ignore")
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