Esempio n. 1
0
    def run(self):
        print ("Loading input and generating...")
        fileload, resolution, format = loadMidi.load('midi/bach_simple.mid')

        stringNotes = convert.listToString(fileload)

        mc = MarkovChain(1)
        mc.add_string(stringNotes)
        markovNotes = ' '.join(mc.generate_text(50))

        writeMidi.writeList(convert.stringToList(markovNotes), resolution, format)
        print ('Process complete, output is in ./rebuilt.mid')
Esempio n. 2
0
def generate_text(input, output):
    if os.path.isfile(args.o):
        os.remove(args.o)
    num_words = args.n

    contents = read_file(input)
    wordlist = contents.split(' ')

    markov = MarkovChain(wordlist)

    with open(output, 'a+') as f:
        f.write(markov.generate_text(num_words))
Esempio n. 3
0
    # Get India trending topics on Twitter
    trends = api.trends_place(23424848)
    data = trends[0]
    trending = [trend['name'] for trend in data['trends']]

    print("Choosing 10 topics at random...")
    shuffle(trending)
    topics = sample(trending, 10)
    for topic in topics:
        print(topic)

    # Get tweets about the topic
    collector = TweetCollector()
    stream = Stream(auth, collector)
    stream.filter(track=topics, languages=['en'])
    print('Finished collecting tweets')

    # Generate "empty" tweets
    tweets = collector.get_tweets()
    mc_model = MarkovChain(tweets)
    mc_model.generate_model()
    mt_tweets = []
    for i in range(50):
        mt_tweets.append(mc_model.generate_text())

    # Choose one at random and update status
    status = choice(mt_tweets)
    print("Tweeting...", status, sep='\n')
    api.update_status(status)