-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMarkov_Tweet.py
47 lines (40 loc) · 1.34 KB
/
Markov_Tweet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sys import argv
from markov_class import *
from keys import *
import tweepy
from tweetdump import *
from csvtotxt import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
def main():
#Order of model - Tweak for better/worse results
order = int(2)
handle = "jack" #Put handle you want to emulate here
get_all_tweets(handle) #COMMENT THIS OUT TO JUST READ FROM LAST READ USER
csvtotext('tweets.csv', 'tweets.txt') #COMMENT THIS OUT TO JUST READ FROM LAST READ USER
filetext = process_file('tweets.txt')
# The number below is determined upon the maximum length of a tweet minus the maximum
# length of a handle.
markov = MarkovDict(filetext, order, 140)
markov.read_text()
output = markov.output_text()
tweet_output(output)
# prompt to open file
def process_file(file):
f = open(file)
print "processed file"
# read through the file
filetext = f.read()
f.close()
return filetext
# Put your keys into "DO_ME_twitter_keys" file and rename the file to "keys.py"
def tweet_output(output):
new = list(output)
print "Status:" + output
api.update_status(output)
print "Tweeted!"
if __name__ == "__main__":
main()