Пример #1
0
def create_tweet(catalyst=''):
	b = Brain(os.path.join(os.path.dirname(__file__), 'cobe.brain'))

	# get a reply from brain, encode as UTF-8
	i = 0

	while True:
		tweet = b.reply(catalyst).encode('utf-8', 'replace')
		if(config.filter_url):
			tweet = remove_url(tweet)
		if(config.filter_hashtag):
			tweet = remove_hashtag(tweet)
		if(config.filter_handle):
			tweet = remove_handle(tweet)
		tweet = smart_truncate(tweet)
		#make sure we're not tweeting something close to something else in the txt files
		#or we can just give up after 100 tries
		if check_tweet(tweet) or i >= 100:
			break
		i += 1
		
	#put the tweet in the db
	db_manager.insert_tweet(tweet)

	return tweet
Пример #2
0
def create_tweet(catalyst='', save_to_history=True):
	b = Brain(os.path.join(os.path.dirname(__file__), 'cobe.brain'))

	# get a reply from brain, encode as UTF-8
	i = 0

	while True:
		tweet = b.reply(catalyst).replace("&gt;", ">").replace("&lt;", "<").replace("&amp;", "&").replace("\"", "").replace("“", "").replace("”", "")
		if config.filter_url:
			tweet = remove_url(tweet)
		if config.filter_hashtag:
			tweet = remove_hashtag(tweet)
		if(config.filter_handle):
			tweet = remove_handle(tweet)
		tweet = smart_truncate(tweet)
		#make sure we're not tweeting something close to something else in the txt files
		#or we can just give up after 300 tries
		if check_tweet(tweet):
			# tweet matches criteria
			if save_to_history==True:
				db_manager.insert_tweet(tweet)
				print "[debug] Saved tweet to twert history database"
			return tweet
		elif i >= 300:
			print "[debug] Failure to create unique tweet. >300 tries"
			return unicode('')

		i += 1
Пример #3
0
def create_tweet(catalyst=''):
    b = Brain(os.path.join(os.path.dirname(__file__), 'cobe.brain'))

    # get a reply from brain, encode as UTF-8
    i = 0

    while True:
        tweet = b.reply(catalyst).encode('utf-8', 'replace')
        if(config['filter_urls']):
            tweet = remove_url(tweet)
        tweet = smart_truncate(tweet)


        # check if last words of tweet are less than 4 and remove them
        last_words_twert = tweet.split(' ')
        while len(last_words_twert[-1]) < 4:
            print "[debug] Removing last word:"+last_words_twert[-1]
            del(last_words_twert[-1])
        tweet = ' '.join(last_words_twert)



        #make sure we're not tweeting something close to something else in the txt files
        #or we can just give up after 100 tries
        if check_tweet(tweet) or i >= 100:
            break
        i += 1
    
    tweet = HTMLParser().unescape(tweet)
    tweet = tweet.upper()
    # clean up miscellaneous characters INCLUDING NUMBERS?
    for ch in ['(',')','1','2','3','4','5','6','7','8','9','0','.',', ,','-,','-;','-.',',,',' ;' ]:
        if ch in tweet:
            tweet=tweet.replace(ch,"")
        if ' TH ' in tweet:
            tweet = tweet.replace(' TH ',' ')
        if ' ND ' in tweet:
            tweet = tweet.replace(' ND ',' ')
        if ' RD ' in tweet:
            tweet = tweet.replace(' RD ',' ')
        if 'THE OF' in tweet:
            tweet = tweet.replace('THE OF ',' ')
        if "  " in tweet:
            tweet = tweet.replace("  "," ")
        if " - " in tweet:
            tweet = tweet.replace(" - "," ")
        if " , " in tweet:
            tweet = tweet.replace(" , ",", ")
    tweet = tweet.rstrip(" ,;=-")
    tweet = tweet.lstrip(" ,;=-?{}[]/_=+")

        
    #put the tweet in the db
    db_manager.insert_tweet(tweet)

    return tweet
Пример #4
0
def create_tweet(catalyst=''):
    b = Brain(os.path.join(os.path.dirname(__file__), 'cobe.brain'))

    # get a reply from brain, encode as UTF-8
    i = 0

    while True:
        tweet = b.reply(catalyst).encode('utf-8', 'replace')
        if (config.filter_url):
            tweet = remove_url(tweet)
        tweet = smart_truncate(tweet)
        #make sure we're not tweeting something close to something else in the txt files
        #or we can just give up after 100 tries
        if check_tweet(tweet) or i >= 100:
            break
        i += 1

    #put the tweet in the db
    db_manager.insert_tweet(tweet)

    return tweet
Пример #5
0
def create_tweet(catalyst=""):
    b = Brain(os.path.join(os.path.dirname(__file__), "cobe.brain"))

    # get a reply from brain, encode as UTF-8
    i = 0

    while True:
        tweet = b.reply(catalyst).encode("utf-8", "replace")
        if config["filter_urls"]:
            tweet = remove_url(tweet)
        tweet = smart_truncate(tweet)
        tweet = quote_fixer(tweet)
        # make sure we're not tweeting something close to something else in the txt files
        # or we can just give up after 100 tries
        if check_tweet(tweet) or i >= 2000:
            break
        i += 1

    tweet = HTMLParser().unescape(tweet)

    # put the tweet in the db
    db_manager.insert_tweet(tweet)

    return tweet
Пример #6
0
        'screen_name': account,
        'count': 200,
        'exclude_replies': True,
        'include_rts': False
    }

    if account in state['accounts']:
        last_tweet = long(state['accounts'][account])
        params['since_id'] = last_tweet
    else:
        last_tweet = 0

    timeline = api.statuses.user_timeline(**params)

    for tweet in timeline:
        b.learn(tweet['text'])
        #add it to the db
        db_manager.insert_tweet(tweet['text'].encode('utf-8', 'replace'),
                                False)
        last_tweet = max(tweet['id'], last_tweet)
        tweets += 1

    print "%d found..." % tweets
    state['accounts'][account] = str(last_tweet)

print "Learning %d tweets" % tweets
b.stop_batch_learning()
#close the learned txt
open(os.path.join(os.path.dirname(__file__), '.state'),
     'w').write(dumps(state))
Пример #7
0
	if account in state['accounts']:
		last_tweet = long(state['accounts'][account])
	else:
		last_tweet = 0

	try:
		timeline = api.GetUserTimeline(
			screen_name=account,
			count=200,
			since_id=last_tweet,
			include_rts=False,
			exclude_replies=True,
			trim_user=True)
	except:
		continue

	for tweet in timeline:
		b.learn(tweet.text)
		#add it to the db
		db_manager.insert_tweet(tweet.text, False)
		last_tweet = max(tweet.id, last_tweet)
		tweets += 1

	print "%d found..." % tweets
	state['accounts'][account] = str(last_tweet)

print "Learning %d tweets" % tweets
b.stop_batch_learning()
#close the learned txt
open(os.path.join(os.path.dirname(__file__), '.state'), 'w').write(dumps(state))
Пример #8
0
		last_tweet = long(state['accounts'][account])
	else:
		last_tweet = 0

	try:
		timeline = api.GetUserTimeline(
			account, count=200, since_id=last_tweet,	
			include_rts=not config.skip_retweets,
			exclude_replies=config.skip_replies,
	
			trim_user=True,
			include_entities=False
		)
	except:
		continue

	for tweet in timeline:
		b.learn(tweet.text)
		#add it to the db
		db_manager.insert_tweet(tweet.text.encode('utf-8', 'replace'), False)
		last_tweet = max(tweet.id, last_tweet)
		tweets += 1

	print "%d found..." % tweets
	state['accounts'][account] = str(last_tweet)

print "Learning %d tweets" % tweets
b.stop_batch_learning()
#close the learned txt
open(os.path.join(os.path.dirname(__file__), '.state'), 'w').write(dumps(state))