简体   繁体   English

用tweepy鸣叫两个不同的元素

[英]Tweeting two different elements with tweepy

I'm trying to tweet two elements with tweepy like: 我正在尝试使用tweepy推特发布两个元素:

api.update_status(item, "-Oliver")

However when I tweet that, it only tweets "item" instead of "Item -Oliver" I tried combining it so 但是,当我发推文时,它仅发推文“ item”而不是“ Item -Oliver”,因此我尝试将其组合

total = item, "-Oliver"
api.update_status(total)

But that tweet looks like: (u'Jake Gyllenhaal', '-Oliver') My code this far is: 但是那条推文看起来像:(u'Jake Gyllenhaal','-Oliver')到目前为止,我的代码是:

#movie loving bot
import requests
import re
from bs4 import BeautifulSoup as BS
import tweepy
from secrets import *

#create OAuthHandler instance
#Twitter requires all requests to use OAuth for authentification
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

auth.set_access_token(access_token, access_secret)

#construct API instance
#entry point for operations performed with twitter 
api = tweepy.API(auth) #create an API object

calcAgain = True
while (calcAgain == True):
    movie = raw_input("What movie u want? If title more than 1 word seperate             with hyphen: ")
    crewType = raw_input("What crew person u want: ")

    link = "https://letterboxd.com/film/%s/" % (movie)
    #requesting page data 
    page = requests.get(link)
    #getting html content from page 
    soup = BS(page.content, 'html.parser')

    easyCrew = ['director', 'actor']

    if crewType in easyCrew:
        crews = soup.find('a', {'itemprop' : crewType})
        crew = crews.find('span', {'itemprop' : 'name'})
        for item in crew:
            total = item, "-Oliver"
            api.update_status(total)

    invalidAns2 = True #checks for valid input 
    while (invalidAns2) == True : #try again loop
        exit = raw_input("Anotha one? (y/n)")
        if exit == 'y' or exit == 'Y': #play again
            invalidAns2 = False  
        elif exit == 'n' or exit == 'N': #end program
            print "Thanks for playing, goodbye!"
            invalidAns2 = False 
            calcAgain = False
        else : 
            print "Please enter y for yes or n for no." #error statement

update_status() expects a text (string) of a tweet as the first argument, concatenate the strings : update_status()希望将tweet的文本(字符串)作为第一个参数, 并连接字符串

total = item + "-Oliver"
api.update_status(total)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM