예제 #1
0
    
    replies = None
    if last_tweet:
        replies = api.statuses.mentions_timeline(since_id=last_tweet)
    else:
        replies = api.statuses.mentions_timeline()
    
    for reply in replies:
        if check_names(reply):
            continue
        
        tweet_text = reply["text"].encode('utf-8', 'replace')
        tweet_text = string.lstrip(tweet_text, "@" + config["screen_name"])
        
        reply_tweet = twert_helper.create_tweet().encode('utf-8', 'replace')
        reply_tweet = twert_helper.smart_truncate('@%s %s' % (reply["user"]["screen_name"].encode('utf-8', 'replace'), reply_tweet))
        if not args.stdout:
            api.statuses.update(status=reply_tweet, in_reply_to_status_id=reply["id"])
        else: 
            print(reply_tweet)
        # except:
        #   print 'Error posting reply.'

        last_tweet = max(reply["id"], last_tweet)
        break

    if not args.stdout:
        state['last_reply'] = str(last_tweet)
        print "Saving state"

open(os.path.join(os.path.dirname(__file__), '.state'), 'w').write(dumps(state))
예제 #2
0
        print "Printing test replies (dry-run)"
    
    last_tweet = long(state['last_reply'])
    
    replies = None
    if last_tweet:
        replies = api.statuses.mentions_timeline(since_id=last_tweet)
    else:
        replies = api.statuses.mentions_timeline()
    
    for reply in replies:
        if check_names(reply):
            continue
        # try:
        reply_tweet = twert_helper.create_tweet(reply["text"].encode('utf-8', 'replace')).encode('utf-8', 'replace')
        reply_tweet = twert_helper.smart_truncate('@%s %s' % (reply["user"]["screen_name"].encode('utf-8', 'replace'), reply_tweet))
        if not args.stdout:
            api.statuses.update(status=reply_tweet, in_reply_to_status_id=reply["id"])
        else: 
            print(reply_tweet)
        # except:
        #   print 'Error posting reply.'

        last_tweet = max(reply["id"], last_tweet)
        break

    if not args.stdout:
        state['last_reply'] = str(last_tweet)
        print "Saving state"

open(os.path.join(os.path.dirname(__file__), '.state'), 'w').write(dumps(state))
예제 #3
0
	replies = api.GetMentions(since_id=last_tweet)
	
	for reply in replies:
		if check_names(reply):
			continue

		reply_tweet = twert_helper.create_tweet(reply.text)
		if len(reply_tweet) == 0:
			# sometimes it can't be done with the catalyst given
			# so create something novel, instead
			reply_tweet = twert_helper.create_tweet()

		# make sure that we don't have a blank tweet
		# otherwise we'll send a blank reply
		if len(reply_tweet) > 0:
			reply_tweet = twert_helper.smart_truncate('@%s %s' % (reply.user.screen_name, reply_tweet))
			if not args.stdout:
				api.PostUpdate(reply_tweet, in_reply_to_status_id=reply.id)
			else: 
				print(reply_tweet)

		# mark it as last tweet either way
		# (in rare circumstances the bot won't reply)
		last_tweet = max(reply.id, last_tweet)

	if not args.stdout:
		state['last_reply'] = str(last_tweet)
		print "Saving state"

open(os.path.join(os.path.dirname(__file__), '.state'), 'w').write(dumps(state))