Created
February 11, 2016 17:19
-
-
Save joechip504/fb646cc81e12400c8060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import docx | |
import markovify | |
import os | |
import pprint | |
import random | |
import sys | |
import wordcloud | |
if __name__ == '__main__': | |
# Usage | |
if len(sys.argv) != 2: | |
sys.exit( | |
'Usage: python3 {} path/to/motivation/folder'.format(sys.argv[0])) | |
# Collect text from all word documents | |
text = '' | |
for root, subdirs, files in os.walk(sys.argv[1]): | |
# Can do some additional filtering to only include files created within | |
# week 1, week 2, etc | |
docs = [f for f in files if f.endswith('.doc') or f.endswith('.docx')] | |
for doc in docs: | |
try: | |
document = docx.Document(os.path.join(root, doc)) | |
text += '\n'.join([str(paragraph.text) | |
for paragraph in document.paragraphs]) | |
except: | |
continue | |
model = markovify.Text(text) | |
sentences = ' '.join([model.make_sentence() | |
for i in range(random.randint(3, 5))]) | |
print(sentences) | |
cloud = wordcloud.WordCloud( | |
font_path="/Library/Fonts/Verdana.ttf", | |
width=1000, | |
height=1000, | |
) | |
cloud.generate(text).to_file('motivation.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment