added support for multiple source accounts and updated generating from static text file

This commit is contained in:
Tom Meagher
2013-10-30 13:11:25 -04:00
parent 98e2954376
commit 5eb83e2986
2 changed files with 21 additions and 13 deletions

View File

@@ -39,23 +39,25 @@ if __name__=="__main__":
guess = 0 guess = 0
if guess == 0: if guess == 0:
if DEBUG==True: if STATIC_TEST==True:
file = TEST_SOURCE file = TEST_SOURCE
print ">>> Generating from {0}".format(file)
string_list = open(file).readlines() string_list = open(file).readlines()
for item in string_list: for item in string_list:
source_tweets = item.split(",") source_tweets = item.split(",")
else: else:
user=SOURCE_ACCOUNT
source_tweets = [] source_tweets = []
api=connect() for handle in SOURCE_ACCOUNTS:
max_id=None user=handle
for x in range(17)[1:]: api=connect()
source_tweets_iter, max_id = grab_tweets(api,max_id) max_id=None
source_tweets += source_tweets_iter for x in range(17)[1:]:
print "{0} tweets found".format(len(source_tweets)) source_tweets_iter, max_id = grab_tweets(api,max_id)
if len(source_tweets) == 0: source_tweets += source_tweets_iter
print "Error fetching tweets from Twitter. Aborting." print "{0} tweets found in {1}".format(len(source_tweets), handle)
sys.exit() if len(source_tweets) == 0:
print "Error fetching tweets from Twitter. Aborting."
sys.exit()
mine = markov.MarkovChainer(order) mine = markov.MarkovChainer(order)
for tweet in source_tweets: for tweet in source_tweets:
if re.search('([\.\!\?\"\']$)', tweet): if re.search('([\.\!\?\"\']$)', tweet):

View File

@@ -1,11 +1,17 @@
'''
Local Settings for a heroku_ebooks account. #fill in the name of the account you're tweeting from here.
'''
#configuration #configuration
MY_CONSUMER_KEY = 'Your Twitter API Consumer Key' MY_CONSUMER_KEY = 'Your Twitter API Consumer Key'
MY_CONSUMER_SECRET = 'Your Consumer Secret Key' MY_CONSUMER_SECRET = 'Your Consumer Secret Key'
MY_ACCESS_TOKEN_KEY = 'Your Twitter API Access Token Key' MY_ACCESS_TOKEN_KEY = 'Your Twitter API Access Token Key'
MY_ACCESS_TOKEN_SECRET = 'Your Access Token Secret' MY_ACCESS_TOKEN_SECRET = 'Your Access Token Secret'
SOURCE_ACCOUNT = "" #The Twitter handle of the account that you'll generate tweets based on. SOURCE_ACCOUNTS = [""] #A list of comma-separated, quote-enclosed Twitter handles of account that you'll generate tweets based on. It should look like ["account1", "account2"]. If you want just one account, no comma needed.
ODDS = 8 #How often do you want this to run? 1/8 times? ODDS = 8 #How often do you want this to run? 1/8 times?
ORDER = 2 #how closely do you want this to hew to sensical? 1 is low and 3 is high. ORDER = 2 #how closely do you want this to hew to sensical? 1 is low and 3 is high.
DEBUG = True #Set this to False to start Tweeting live DEBUG = True #Set this to False to start Tweeting live
TEST_SOURCE = "" #The name of a text file of a string-ified list for testing. To avoid unnecessarily hitting Twitter API. STATIC_TEST = False #Set this to True if you want to test Markov generation from a static file instead of the API.
TEST_SOURCE = ".txt" #The name of a text file of a string-ified list for testing. To avoid unnecessarily hitting Twitter API.
TWEET_ACCOUNT = "" #The name of the account you're tweeting to.