Last active
June 17, 2017 11:49
-
-
Save giubil/27d015c7a3ac196967de0b3deb05b9ff 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
#!/usr/bin/env python3 | |
import markovify | |
import argparse | |
import json | |
def parse_arguments(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("data_dir", help="The path to the directory containing your messages, extracted with fbchat-archive-parser, in json format") | |
args = parser.parse_args() | |
return args.data_dir | |
def get_all_messages_from_participant(convo): | |
participant = convo['participants'][0] | |
buff_convo = convo["messages"] | |
corpus = "" | |
for elem in buff_convo: | |
if elem['sender'] == participant: | |
corpus = corpus + elem['message'] + "\n" | |
return corpus | |
def main(): | |
data_dir = parse_arguments() | |
f = open(data_dir + "/manifest.txt", "r") | |
f.readline() | |
f.readline() | |
for line in f: | |
print (line, end='') | |
f.close() | |
convo_number = input("Please enter the number of the convo you want to analyse : ") | |
f = open(data_dir + "thread_{}.json".format(convo_number), "r") | |
convo = json.load(f) | |
f.close() | |
corpus = get_all_messages_from_participant(convo) | |
model = markovify.NewlineText(corpus) | |
print(chr(27) + "[2J") | |
while True: | |
print (model.make_sentence(), end='') | |
input("") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To generate the files needed for this to work, you need to download the archive facebook provides with all your contents.
Then you need to install a package that parses those files :
And then launch the extraction (I recommend using --resolve, which requires your facebook crendentials, to resolve facebook ids to logins)
Then launch this script :