<commit_before>import markovify
import sys
import argparse
import configparser
import twitter

def main():
	arg_parser = argparse.ArgumentParser(description="Generate text with Markov chains based on a source corpus.")
	subparser = arg_parser.add_subparsers(dest="subparser_name")

	subparser_train = subparser.add_parser("train")
	subparser_train.add_argument("corpus", help="Path to a corpus to train with.")
	subparser_train.add_argument("savepath", help="Path to where to save the model, in JSON format.")

	subparser_tweet = subparser.add_parser("tweet")
	subparser_tweet.add_argument("corpus", help="Path to a corpus.")
	subparser_tweet.add_argument("modelpath", help="Path to a model built with \"train\"")

	args = arg_parser.parse_args()

	config = configparser.ConfigParser()
	config.read("poorlytrained.ini")
	twitter_consumer_key = config["keys"]["consumerkey"]
	twitter_consumer_secret = config["keys"]["consumersecret"]
	twitter_access_token = config["keys"]["accesstoken"]
	twitter_access_token_secret = config["keys"]["accesstokensecret"]

	if(args.subparser_name == "train"):
		with open(args.corpus) as f:
			text = f.read()

		text_model = markovify.Text(text)

		with open(args.savepath, "w") as f:
			f.write(text_model.chain.to_json())

	elif(args.subparser_name == "tweet"):
		with open(args.corpus) as corpus:
			with open(args.modelpath) as model:
				model_chain = markovify.Chain.from_json(model.read())
				text_model = markovify.Text(corpus.read(), 2, model_chain)

		tweet_message = text_model.make_short_sentence(140)
		print(tweet_message)
if __name__ == "__main__":
	main()
<commit_msg>Finish implementing tweet capabilities.<commit_after>import markovify
import sys
import argparse
import configparser
import twitter

def main():
	arg_parser = argparse.ArgumentParser(description="Generate text with Markov chains based on a source corpus.")
	subparser = arg_parser.add_subparsers(dest="subparser_name")

	subparser_train = subparser.add_parser("train")
	subparser_train.add_argument("corpus", help="Path to a corpus to train with.")
	subparser_train.add_argument("savepath", help="Path to where to save the model, in JSON format.")

	subparser_tweet = subparser.add_parser("tweet")
	subparser_tweet.add_argument("corpus", help="Path to a corpus.")
	subparser_tweet.add_argument("modelpath", help="Path to a model built with \"train\"")

	args = arg_parser.parse_args()

	config = configparser.ConfigParser()
	config.read("poorlytrained.ini")
	twitter_consumer_key = config["keys"]["consumerkey"]
	twitter_consumer_secret = config["keys"]["consumersecret"]
	twitter_access_token = config["keys"]["accesstoken"]
	twitter_access_token_secret = config["keys"]["accesstokensecret"]

	if(args.subparser_name == "train"):
		with open(args.corpus) as f:
			text = f.read()

		text_model = markovify.Text(text)

		with open(args.savepath, "w") as f:
			f.write(text_model.chain.to_json())

	elif(args.subparser_name == "tweet"):
		with open(args.corpus) as corpus:
			with open(args.modelpath) as model:
				model_chain = markovify.Chain.from_json(model.read())
				text_model = markovify.Text(corpus.read(), 2, model_chain)

		tweet_message = text_model.make_short_sentence(140)
		print(tweet_message)

		tapi = twitter.Api(twitter_consumer_key, twitter_consumer_secret, twitter_access_token, twitter_access_token_secret)
		tapi.PostUpdate(tweet_message)
if __name__ == "__main__":
	main()

{'fraction_non_alphanumeric': 0.12437810945273632, 'fraction_numerical': 0.002341235001463272, 'mean_word_length': 6.350537634408602, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '61123', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1119, 'n_words': 235}