Skip to content

Instantly share code, notes, and snippets.

@viklund
Created October 18, 2017 09:09
Show Gist options
  • Save viklund/94a0bb6d7d5bc697a98a1aa6bbc0054c to your computer and use it in GitHub Desktop.
Save viklund/94a0bb6d7d5bc697a98a1aa6bbc0054c to your computer and use it in GitHub Desktop.
import markovify
import json
import os
users = json.load(open('slack/users.json'))
user = ''
for u in users:
if u['name'] == 'viklund':
user = u['id']
all_text = []
for path, _, files in os.walk('slack/'):
for file in files:
fullpath = path + '/' + file
dump = json.load(open(fullpath))
for message in dump:
if message.get('user', '') == user:
if 'text' in message and message['text']:
all_text.append( message['text'] )
text_model = markovify.Text(all_text, state_size=3)
n = 20
tot = 0
while tot < n:
sentence = text_model.make_sentence(max_overlap_ratio=0.4)
if sentence:
print(sentence)
tot+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment