Advertisement
dado3212

Read Messages

Mar 2nd, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import sqlite3, markovify, codecs, warnings
  4.  
  5. # Handle errors from running on Python 2.7 (emoji support)
  6. warnings.simplefilter("ignore")
  7.  
  8. # Extract all of my texts from the 'db' file
  9. conn = sqlite3.connect('sms.db')
  10. c = conn.cursor()
  11. c.execute('SELECT text, `date` FROM message WHERE text != "" AND is_from_me = 1')
  12. mine = c.fetchall()
  13.  
  14. # Combine all of the messages into one giant string
  15. text = ". ".join([x[0] for x in mine])
  16. f = codecs.open('message.txt', 'w', 'utf-8')
  17. f.write(text)
  18. f.close()
  19.  
  20. # Load that text file in, and generate the markov file
  21. text_model = markovify.Text(text)
  22.  
  23. # Print a sentence every time you press 'enter'
  24. print "Press 'Enter' for a Markov sentence based off of texts.\n"
  25. while True:
  26.   i = raw_input()
  27.   print '\033[{}C\033[1A'.format(1),
  28.   if not i:
  29.     print text_model.make_sentence()
  30.   else:
  31.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement