Skip to content

Instantly share code, notes, and snippets.

@dado3212

dado3212/SearchTexts.py

Last active Sep 29, 2017
Embed
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)
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