Python 如何使用tweepy发布字符串以外的内容

Python 如何使用tweepy发布字符串以外的内容,python,python-2.7,tweepy,Python,Python 2.7,Tweepy,我正在尝试用生成的文本更新我的Twitter状态。到目前为止,生成文本效果很好,但我无法发布到Twitter import tweepy import SentenceGenerator with open('Ratschlaege.txt','r') as textfile: #load the text to analyze sample_text = textfile.read() #Generating one sentence: #print SentenceGenerator.

我正在尝试用生成的文本更新我的Twitter状态。到目前为止,生成文本效果很好,但我无法发布到Twitter

import tweepy

import SentenceGenerator

with open('Ratschlaege.txt','r') as textfile: #load the text to analyze
sample_text = textfile.read()

#Generating one sentence:
#print SentenceGenerator.generate_sentence(sample_text)

#Generating a paragraph:
sentences = 1
print ' '.join([SentenceGenerator.generate_sentence(sample_text) for i        in xrange(sentences)])


# Consumer keys and access tokens, used for OAuth
consumer_key = 'xxx'
consumer_secret = 'xxx'
access_token = 'xxx'
access_token_secret = 'xxx'

# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)     
# Creation of the actual interface, using authentication
api = tweepy.API(auth)         
# Sample method, used to update a status
api.update_status(' '.join([SentenceGenerator.generate_sentence(sample_text) for i in xrange(sentences)]))
据我所知,您可以发布字符串,也可以从文件中发布,但不能发布新生成的文本。 有办法吗

--编辑-- 好吧,我试着在我的脚本中构建一个函数,如下所示

def tweet (tweet):
    tweet = ' '.join([SentenceGenerator.generate_sentence(sample_text) for i in xrange(sentences)])
    # Consumer keys and access tokens, used for OAuth
    consumer_key = 'xxx'
    consumer_secret = 'xxx'
    access_token = 'xxx'
    access_token_secret = 'xxx'

    # OAuth process, using the keys and tokens
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)     
    # Creation of the actual interface, using authentication
    api = tweepy.API(auth)         
    # Sample method, used to update a status
    api.update_status(tweet)        
time.sleep(10)
现在它运行,每10秒在一个循环中测试一次,没有显示错误,但状态不会更新。它运行起来就像它应该做的一样,只是它不发推特。 我错过了什么

--编辑--

我还添加了一个将生成的文本插入MySQL数据库的部分

db = MySQLdb.connect ( host ='127.0.0.1',
                       user = 'Daniel',
                       passwd = 'localhost')
        cur = db.cursor()
        cur.execute("insert into multigram (Ratschlag) value ('%s')" % (tweet))
此处相同:没有错误消息,但数据库中也没有条目。
我确信这很容易解决,但我不知道我做错了什么。

运行此脚本时会发生什么?什么是句子生成器?»句子生成器«是另一个Python脚本。这是一个生成文本的马尔可夫链。有了这个脚本,你激活它,它就会打印出一个生成的句子。一切都很好,我想做的就是推特生成的句子,一个与打印命令不同的命令…如果不看SentenceGenerator,很难说,你的tweepy代码看起来是正确的。是否可以通过打印到标准输出检查输出?