Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import sqlite3, markovify, codecs, warnings
- # Handle errors from running on Python 2.7 (emoji support)
- warnings.simplefilter("ignore")
- # Extract all of my texts from the 'db' file
- conn = sqlite3.connect('sms.db')
- c = conn.cursor()
- c.execute('SELECT text, `date` FROM message WHERE text != "" AND is_from_me = 1')
- mine = c.fetchall()
- # Combine all of the messages into one giant string
- text = ". ".join([x[0] for x in mine])
- f = codecs.open('message.txt', 'w', 'utf-8')
- f.write(text)
- f.close()
- # Load that text file in, and generate the markov file
- text_model = markovify.Text(text)
- # Print a sentence every time you press 'enter'
- print "Press 'Enter' for a Markov sentence based off of texts.\n"
- while True:
- i = raw_input()
- print '\033[{}C\033[1A'.format(1),
- if not i:
- print text_model.make_sentence()
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement